To get an XML-type object:
Copy Code code as follows:
$resp = $this->c->execute ($req, $sessionKey);//Get XML Object
$items = $resp->items;
Then read the value of the object, use $items->item, or $items->item->price, so it is inconvenient to operate, does not conform to the custom of PHP operation array.
PHP provides an array method for converting objects into arrays, just by adding (array) to the object you want to convert the array to.
For example, convert $items->item (objects with many item) to an array:
Copy Code code as follows:
foreach ($items->item as $item) {
$goods []= (array) $item;
}
$goods is an array of PHP.
Before conversion:
Copy Code code as follows:
SimpleXMLElement Object
(
[CID] => 50003793
[Modified] => 2013-04-18 17:16:25
[Nick] => qq307819623
[Price] => 200.00
[title] => Nokia N97 New licensed
)
SimpleXMLElement Object
(
[CID] => 50024921
[Modified] => 2013-04-18 16:58:06
[Nick] => qq307819623
[Pic_url] =>pic.jpg
[Price] => 888888.00
[title] => Liu Junzhong
)
SimpleXMLElement Object
(
[CID] => 1512
[Modified] => 2013-04-18 16:56:46
[Nick] => qq307819623
[Pic_url] => item_pic.jpg
[Price] => 323232.00
[title] => Second-hand Hello
)
SimpleXMLElement Object
(
[CID] => 50012166
[Modified] => 2013-04-18 15:10:07
[Nick] => qq307819623
[Pic_url] =>0-item_pic.jpg
[Price] => 32.00
[title] => magnification Radski a crazy idea. Lars Law
)
After conversion:
Copy Code code as follows:
Array
(
[0] => Array
(
[CID] => 50003793
[Modified] => 2013-04-18 17:16:25
[Nick] => qq307819623
[Price] => 200.00
[title] => Nokia N97 New licensed
)
[1] => Array
(
[CID] => 50024921
[Modified] => 2013-04-18 16:58:06
[Nick] => qq307819623
[Pic_url] => pic.jpg
[Price] => 888888.00
[title] => Liu Junzhong
)
[2] => Array
(
[CID] => 1512
[Modified] => 2013-04-18 16:56:46
[Nick] => qq307819623
[Pic_url] =>item_pic.jpg
[Price] => 323232.00
[title] => Second-hand Hello
)
[3] => Array
(
[CID] => 50012166
[Modified] => 2013-04-18 15:10:07
[Nick] => qq307819623
[Pic_url] => 0-item_pic.jpg
[Price] => 32.00
[title] => magnification Radski a crazy idea. Lars Law
)