SauronZ
SauronZ

Reputation: 355

Acces object in an array with php

Hope you can help me.

I've tried so diffrent ways but i'm not able to resolve this problem.

I have an array with objects inside:

    Array
(
[1] => CntProviderIncentiveResult Object
    (
        [_StartDate:protected] => 1356303600
        [_EndDate:protected] => 1356908400
        [_ProviderRoom:CntProviderIncentiveResult:private] => 1
        [_RoomName:CntProviderIncentiveResult:private] => Doble
        [_RoomCode:CntProviderIncentiveResult:private] => 2370
        [_PropertyCode:CntProviderIncentiveResult:private] => anglers
        [_Occupancy:CntProviderIncentiveResult:private] => 
        [_Currency:CntProviderIncentiveResult:private] => 
        [_AllocationGroup:CntProviderIncentiveResult:private] => 
        [_FreeSaleGroup:CntProviderIncentiveResult:private] => 
        [_StopSaleGroup:CntProviderIncentiveResult:private] => 
        [_ReleaseGroup:CntProviderIncentiveResult:private] => 
        [_MinStayGroup:CntProviderIncentiveResult:private] => 
        [_UpdateRequirement:CntProviderIncentiveResult:private] => 

) )

I try to assign one of the objects to a new array setting the Array Key:

$ConfirmRoom = $ConfirmRoomData[$roomKey];

Where $roomKey is the Key of the array. (1, 20, 21)

and after i verify if is well done:

if ($ConfirmRoom instanceof CntProviderIncentiveResult) {echo "OK";} 

But The new object $ConfirmRoom is always empty.

Could you please make me see the light?

Upvotes: 1

Views: 74

Answers (2)

SauronZ
SauronZ

Reputation: 355

Finally i solved:

foreach ($ConfirmRoomData as $key => $value) {
if (is_object ($value)) {
if ($key == $roomKey){
                                            $ConfirmRoom = $value;
}

} }

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324630

Try var_dump($ConfirmRoom) for starters.

Also, ensure that isset($ConfirmRoomData[$roomKey]) and that the big array is indeed in $ConfirmRoomData.

These are just a few basic debugging steps that may help solve your problem. My guess would be that $roomKey is not being properly defined.

Upvotes: 1

Related Questions