3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "id": "220", "pin_list": [ { "id": "1", "name": "1. La Sagrada Familia" }, { "id": "2", "name": "2. Park Guell" }, { "id": "3", "name": "10. Casa Batllo" }, { "id": "4", "name": "11. Cathedral of Barcelona" }, { "id": "5", "name": "3. Picasso Museum" }, { "id": "6", "name": "Zebra" }, { "id": "7", "name": "Apple" }, { "id": "8", "name": "Monkey" } ] }'; $array = json_decode($json, true); usort($array['pin_list'], function ($a, $b) { return strnatcmp($a['name'], $b['name']); }); echo json_encode($array, JSON_PRETTY_PRINT);
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.30, 7.4.0 - 7.4.23, 8.0.0 - 8.0.11, 8.1rc1 - rc2
{ "id": "220", "pin_list": [ { "id": "1", "name": "1. La Sagrada Familia" }, { "id": "2", "name": "2. Park Guell" }, { "id": "5", "name": "3. Picasso Museum" }, { "id": "3", "name": "10. Casa Batllo" }, { "id": "4", "name": "11. Cathedral of Barcelona" }, { "id": "7", "name": "Apple" }, { "id": "8", "name": "Monkey" }, { "id": "6", "name": "Zebra" } ] }

preferences:
77.54 ms | 461 KiB | 5 Q