Question : get item in array

Ok. I know simple..  I seem to be brain farting here..

I have this..
$RF = new CloudFlavor($Auth);
$RF_Result = $RF->listFlavors(true);

print_r($RF_Result);

where that prints..

stdClass Object
(
    [flavors] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1
                    [ram] => 256
                    [disk] => 10
                    [name] => 256 server
                )
)
)

So to get the id out I need to do..

foreach($RF_Result['flavors'] as $key => $flavor)
echo 'id:'.$flavor['id']);
      print_r($flavor);
}


so it should have looked like

stdClass Object
(
    [flavors] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1
                    [ram] => 256
                    [disk] => 10
                    [name] => 256 server
                )
)
)

id:1


stdClass Object
                (
                    [id] => 1
                    [ram] => 256
                    [disk] => 10
                    [name] => 256 server
                )


what is the foreach suppost to be here.. tk

Answer : get item in array

flavors is an object not an array according to print_r, then in turn that is an array of objects (not an array of arrays)

I believe you you are looking for is:
1:
2:
3:
4:
foreach($RF_Result->flavors as $key => $flavor)
echo 'id:'.$flavor->id);
      print_r($flavor);
}
Random Solutions  
 
programming4us programming4us