CARASS
CARASS

Reputation: 245

Counting variables values from $_REQUEST

My $_REQUEST is the below

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
)

I am trying to count the adults and childs from both rooms

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

but the result is 0 , Any ideea ?

Upvotes: 0

Views: 71

Answers (1)

Kamil Karkus
Kamil Karkus

Reputation: 1283

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

well $_REQUEST is not instance of stdClass, it's an array, so you can access it like an array

Upvotes: 4

Related Questions