3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Uncaught TypeError: usort(): Argument #1 ($array) must be of type array, stdClass given in /in/u7PTt:23 Stack trace: #0 /in/u7PTt(23): usort(Object(stdClass), 'sortByText') #1 {main} thrown in /in/u7PTt on line 23
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
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.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 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" } }

preferences:
174.85 ms | 403 KiB | 228 Q