simplexml - create php array using simpleXMLobject -


i'm trying array ($resdata) object(simplexmlelement) php array:

$resdata =  array(59) {  [0]=> ... [10]=> object(simplexmlelement)#294 (28) {  ["reservation_id"]=> string(7) "8210614"  ["event_id"]=> string(6) "279215" ["space_reservation"]=> array(2) {       [0]=> object(simplexmlelement)#344 (9) {      ["space_id"]=> string(4) "3760"      ["space_name"]=> string(9) "205"      ["formal_name"]=> string(33) "center" }       [1]=> object(simplexmlelement)#350 (9) {      ["space_id"]=> string(4) "3769"      ["space_name"]=> string(9) "207"      ["formal_name"]=> string(32) "right" } } }  } 

i've tried:

$res = (array)$resdata; $reservation = $res['reservation']; $result = array();  foreach ($reservation $key => $value){ $res = array($value); $spid = $res[0]->space_reservation->space_id; echo $value->event_id."<br />"; echo $spid."<br />"; } 

this outputs first space_id , need space_ids within "space_reservation" array. not records have multiple space_ids. pointing me in right direction appreciated. not sure if should use xpath need re-write foreach statement regardless.

i hoping able literally convert references "object(simplexmlelement)#_ (#)" "array(#)"

[10]=> array (28) {  ["reservation_id"]=> string(7) "8210614"  ["event_id"]=> string(6) "279215" ["space_reservation"]=> array(2) {       [0]=> array (9) {      ["space_id"]=> string(4) "3760"      ["space_name"]=> string(9) "205"      ["formal_name"]=> string(33) "center" }       [1]=> array (9) {      ["space_id"]=> string(4) "3769"      ["space_name"]=> string(9) "207"      ["formal_name"]=> string(32) "right" } } }  } 

the function in cakephp 1.3 controller this:

$xml = simplexml_load_string($string); $this->data['events']= $xml->children(); $resdata = $this->data['events']; $this->set('resdata',$resdata); 

i think should looking for:

foreach ($resdata $res) {     echo $res->event_id . '<br />';     foreach ($res->space_reservation $reservation) {         echo $reservation->space_id . '<br />';     } } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -