<?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);
You have javascript disabled. You will not be able to edit any code.