计算 $_REQUEST 起的变量值


Counting variables values from $_REQUEST

我的$_REQUEST如下

Array
(
    [city] => Antalya
    [country] => Turcia
    [DesinationId] => A99O
    [In] => 2015-04-29
    [Out] => 2015-05-01
    [rooms] => Array
        (
            [0] => Array
                (
                    [adult] => 2
                    [child] => 0
                )
            [2] => Array
                (
                    [adult] => 1
                    [child] => 0
                )
        )
    [PHPSESSID] => 195897227bcf5ff2772632d7063b7ba7
    [_ga] => GA1.2.45498464.1425755756
)

我正在尝试计算两个房间的成人和儿童

$adults = ($_REQUEST->rooms[0]->adult + $_REQUEST->rooms[2]->adult)

但结果是0,有没有想法?

$adults = ($_REQUEST['rooms'][0]['adult'] + $_REQUEST['rooms'][2]['adults']);

好吧$_REQUEST不是stdClass的实例,它是一个数组,所以你可以像数组一样访问它