3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = '<?xml version="1.0" encoding="utf-8" ?> <note> <to> <form>D</form> <heading>E</heading> <body>F</body> </to> <to> <form>A</form> <heading>B</heading> <body>C</body> </to> </note>'; $xml = simplexml_load_string($data); foreach ($xml->to as $to) { if ($to->form == 'A') { // našel jsem <to>, ve kterém je <form>A</form> // a tady s ním můžu pracovat echo "heading: ".$to->heading."\nbody: ".$to->body; } }
Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.23, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.30, 8.0.0 - 8.0.23, 8.1.0 - 8.1.10
heading: B body: C

preferences:
51.52 ms | 410 KiB | 5 Q