3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = [ 'this' => 'that', 'and' => 'the', 'other' => (object) [ 'layers' => 'make', 'things' => 'more', 'fun' => (object) [ 'every' => 'time', 'foo' => 'bar', ], ], ]; // Just sort and return the sorted array function array_ksort(array $array) { ksort($array); return $array; } $obj = (object) array_ksort(array_map(function($value) { return !is_object($value) ? $value : (object) array_ksort((array) $value);}, $obj)); var_dump($obj);

preferences:
28.34 ms | 406 KiB | 5 Q