3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xmlstr = <<<XML <xml> <medium val="organic"> <source val=""> <campaign val=""> <lever3 val="seo">foo</lever3> <lever2 val="seo">bar</lever2> <lever1 val="trafic_gratuit" /> </campaign> </source> </medium> <medium val="cpc"> <source val=""> <campaign val="remarketing"> <lever3 val="sem-remarketing" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> </source> <source val="leguide"> <campaign val=""> <lever3 val="comparateur-leguide" /> <lever2 val="comparateur" /> <lever1 val="trafic_payant" /> </campaign> </source> <source val="google"> <campaign val="marque"> <lever3 val="sem-marque-google" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="auchan-fil_rouge"> <lever3 val="sem-marque-google" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="horsmarque"> <lever3 val="sem-hors-marque-google" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> </source> <source val="bing"> <campaign val="auchan-fil_rouge"> <lever3 val="sem-marque-yahoo_bing" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="marque"> <lever3 val="sem-marque-yahoo_bing"/> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="horsmarque"> <lever3 val="sem-horsmarque-yahoo_bing"/> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> </source> </medium> <medium val="cpa"> <source val="affilinet"> <campaign val=""> <lever3 val="affiliation" /> <lever2 val="affiliation" /> <lever1 val="trafic_payant" /> </campaign> </source> </medium> </xml> XML; $xml = new SimpleXMLElement($xmlstr); $medium_val = "cpc"; $source_val = "bing"; $campaign_val = "horsmarque"; $results = $xml->xpath("//medium[@val='{$medium_val}']/source[@val='{$source_val}']/campaign[@val='{$campaign_val}']/*"); $leviers = array("levier3", "levier2", "levier1"); foreach ($results as $key => $result) { echo " {$leviers[$key]} => {$result->attributes()}\n"; }
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
levier3 => sem-horsmarque-yahoo_bing levier2 => sem levier1 => trafic_payant
Output for 4.4.3 - 4.4.9
Parse error: syntax error, unexpected '(', expecting '}' in /in/Ov8Zg on line 86
Process exited with code 255.
Output for 4.4.2
Parse error: syntax error, unexpected '(', expecting '}' in /in/Ov8Zg on line 87
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '(', expecting '}' in /in/Ov8Zg on line 86
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'}'' in /in/Ov8Zg on line 86
Process exited with code 255.