3v4l.org

run code in 500+ PHP versions simultaneously
<?php $xml = '<products> <group> <product id="853" symbol="XYZ123" stock="73"></product> <product id="941" symbol="ERX412" stock="57"></product> <product id="1960" symbol="UIX981" stock="21"></product> </group> </products>'; $ids = [853, 1960]; $array = json_decode(json_encode((array)simplexml_load_string($xml)),true); foreach($array['group']['product'] as $v){ $cur = $v['@attributes']['id']; $stock = $v['@attributes']['stock']; in_array($cur, $ids) ? ($res[$cur] = $stock) : ''; } print_r($res);
Output for rfc.property-hooks, git.master, git.master_jit
Array ( [853] => 73 [1960] => 21 )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
51.64 ms | 1698 KiB | 4 Q