Closed xr0m3oz closed 8 years ago
Use SimpleXMLElement::attributes() method: http://php.net/manual/en/simplexmlelement.attributes.php foreach ($offer->param->attributes() as $key=> $item)
Атрибуты искомого элемента получаются в нормальном виде с Ключ:значение. ` SimpleXMLElement Object ( [@attributes] => Array ( [available] => true [id] => 125800401 )
[categoryId] => 11312
[currencyId] => USD
[delivery] => true
[description] => Geneva Non - functioning Sub - dials Ladies Quartz Watch with Plastic Band
[goodsNumber] => 999
[goodsStatus] => New
[local_delivery_cost] => 0
[manufacturer_warranty] => false
[modified_time] => 1458658728
[name] => Geneva Non - functioning Sub - dials Ladies Quartz Watch with Plastic Band
[oldprice] => 10.85
[oriCountry] => CN
[param] => Array
(
[0] => Geneva
[1] => Female table
[2] => White
[3] => Diamond
[4] => Quartz watch
[5] => Round
[6] => Analog
[7] => Alloy
[8] => Plastic
[9] => Folding clasp with safety
[10] => Decorating small sub-dials
[11] => 1.0 cm / 0.4 inches
[12] => 4.2 cm / 1.65 inches
[13] => 2.0 cm / 0.79 inches
[14] => 0.063 kg
[15] => 0.113 kg
[16] => 14 x 4.2 x 1 cm / 5.50 x 1.65 x 0.39 inches
[17] => 15 x 5.2 x 2 cm / 5.90 x 2.04 x 0.79 inches
[18] => 1 x Geneva Watch
)
[pickup] => false
[picture] => Array
(
[0] => http://gloimg.gearbest.com/gb/2015/201504/goods-img/1428950360886-P-2535778.jpg
[1] => http://gloimg.gearbest.com/gb/2015/201504/goods-img/1428950361372-P-2535778.jpg
[2] => http://gloimg.gearbest.com/gb/2015/201504/goods-img/1428950361737-P-2535778.jpg
[3] => http://gloimg.gearbest.com/gb/2015/201504/goods-img/1428950361082-P-2535778.jpg
)
[postCountry] => CN
[price] => 9.04
[store] => false
[topseller] => true
[transportFee] => 0
[transportTime] => 25
[url] => https://ad.admitad.com/g/2316b8f85670d6392e6522af2ed61b/?i=5&ulp=http%3A%2F%2Fwww.gearbest.com%2Fwomen-s-watches%2Fpp_174857.html
) `
Меня интересует как можно сделать тут [param] => Array ассоциативный массив.
С cкриншот примера элемента xml
$params = iterator_to_array($offer->param);
$params = array_combine(array_map(function($i) {
return (string)$i->name;
}, $params), array_map(function($k, $v) {
return (string)$i;
}, $params));
`
XiaoMi 4G Smartphone Android 5.1 `
Can i get attribute in view key_name=>value
Now i can get
foreach ($offer->param as $key=> $item) { echo "name:".$item."<br>"; }
[0]=>XiaoMi [1]=>4G SmartphoneCan i get
[Brand]=>XiaoMi [Type]=>4G Smartphone