3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = '<?xml version="1.0"?><toplevel><CompleteSuggestion><suggestion data="google"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google maps"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google translate"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google docs"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google drive"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google classroom"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google news"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google earth"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google flights"/></CompleteSuggestion><CompleteSuggestion><suggestion data="google calendar"/></CompleteSuggestion></toplevel>'; $xml = simplexml_load_string($str); $data = json_decode(json_encode($xml),true); echo "ARRAY: <pre>"; var_dump($data);
Output for 5.5.27 - 5.5.38, 5.6.11 - 7.2.0
ARRAY: <pre>array(1) { ["CompleteSuggestion"]=> array(10) { [0]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(6) "google" } } } [1]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google maps" } } } [2]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(16) "google translate" } } } [3]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google docs" } } } [4]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(12) "google drive" } } } [5]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(16) "google classroom" } } } [6]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google news" } } } [7]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(12) "google earth" } } } [8]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(14) "google flights" } } } [9]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(15) "google calendar" } } } } }
Output for 5.5.12 - 5.5.26, 5.6.0 - 5.6.10
ARRAY: <pre>array(1) { ["CompleteSuggestion"]=> array(10) { [0]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(6) "google" } } } [1]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google maps" } } } [2]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(16) "google translate" } } } [3]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google docs" } } } [4]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(12) "google drive" } } } [5]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(16) "google classroom" } } } [6]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google news" } } } [7]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(12) "google earth" } } } [8]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(14) "google flights" } } } [9]=> array(1) { ["suggestion"]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(15) "google calendar" } } } } }
Output for 5.5.0 - 5.5.11
ARRAY: <pre>array(1) { ["CompleteSuggestion"]=> array(10) { [0]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(6) "google" } } } [1]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google maps" } } } [2]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(16) "google translate" } } } [3]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google docs" } } } [4]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(12) "google drive" } } } [5]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(16) "google classroom" } } } [6]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(11) "google news" } } } [7]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(12) "google earth" } } } [8]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(14) "google flights" } } } [9]=> array(1) { [0]=> array(1) { ["@attributes"]=> array(1) { ["data"]=> string(15) "google calendar" } } } } }