从$ _REQUEST计算变量值

时间:2015-03-08 09:34:47

标签: php

我的$ _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,任何想法?

1 个答案:

答案 0 :(得分:4)

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

$_REQUEST不是stdClass的实例,它是一个数组,因此您可以像数组一样访问它