3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @link http://stackoverflow.com/questions/28965063/php-access-array-within-xml */ $buffer = <<<XML <root> <merchant id="1" name="companyname"> <prod id="690579815" lang="en" pre_order="no" web_offer="yes" in_stock="yes">product #1</prod> <prod id="250544605" lang="en" pre_order="no" web_offer="yes" in_stock="yes">product #2</prod> <prod id="360355798" lang="en" pre_order="no" web_offer="yes" in_stock="yes">product #3</prod> </merchant> </root> XML; $data = simplexml_load_string($buffer); var_dump($data['prod']); var_dump(count($data['prod'])); $merchant = $data->merchant; var_dump(count($merchant->prod)); var_dump($merchant->prod[0]->asXML()); var_dump($merchant->prod[0]['id']->asXML()); var_dump((string)$merchant->prod[0]); var_dump((string)$merchant->prod[0]['id']); echo $merchant->prod[0]; // prints: "product #1" echo "\n"; foreach ($merchant->prod as $prod) { echo $prod->asXML(), "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
NULL Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /in/HuLc7:19 Stack trace: #0 {main} thrown in /in/HuLc7 on line 19
Process exited with code 255.

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:
64.18 ms | 401 KiB | 8 Q