3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $js = '{ "BHS": { "text": "Beacon Hill School", "optgroup": "Kowloon" }, "HSK": { "text": "ESF International Kindergarten (Hillside)", "optgroup": "Hong Kong Island" }, "KJS": { "text": "Kowloon Junior School", "optgroup": "Kowloon" } }'; $json = json_decode($js); function sortByText($a, $b) { return ord($a['text'][0]) - ord($b['text'][0]); } usort($json, 'sortByText'); var_dump($json);
Output for 7.0.0 - 7.2.0
Warning: usort() expects parameter 1 to be array, object given in /in/u7PTt on line 23 object(stdClass)#2 (3) { ["BHS"]=> object(stdClass)#1 (2) { ["text"]=> string(18) "Beacon Hill School" ["optgroup"]=> string(7) "Kowloon" } ["HSK"]=> object(stdClass)#3 (2) { ["text"]=> string(41) "ESF International Kindergarten (Hillside)" ["optgroup"]=> string(16) "Hong Kong Island" } ["KJS"]=> object(stdClass)#4 (2) { ["text"]=> string(21) "Kowloon Junior School" ["optgroup"]=> string(7) "Kowloon" } }
Output for 5.3.18 - 5.6.28
Warning: usort() expects parameter 1 to be array, object given in /in/u7PTt on line 23 object(stdClass)#1 (3) { ["BHS"]=> object(stdClass)#2 (2) { ["text"]=> string(18) "Beacon Hill School" ["optgroup"]=> string(7) "Kowloon" } ["HSK"]=> object(stdClass)#3 (2) { ["text"]=> string(41) "ESF International Kindergarten (Hillside)" ["optgroup"]=> string(16) "Hong Kong Island" } ["KJS"]=> object(stdClass)#4 (2) { ["text"]=> string(21) "Kowloon Junior School" ["optgroup"]=> string(7) "Kowloon" } }