3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => array ( 'category' => 'Sink', 'sublineitems' => array ( 0 => array ( 'quantity' => 1, 'model' => 'PBMS2016-12-X', 'customerspecificpricings' => array ( ), 'electricalutilitygrids' => array ( ), 'plumbingutilitygrids' => array ( 0 => array ( 'remarks' => '3-1/2" drain opening', ), ), 'subline_item_id' => '844b7c74-b1b7-4f17-a2da-f0c84cef432d', 'item_type_code' => 0, 'item_type_description' => 'Normal', 'vendor_id' => '4e1ab2ef-774e-4c73-be60-c937d1efeb56', ), ), 'lineitem_id' => 'e592feab-1e1a-4cfc-a97a-f1108c7156b6', 'item_number' => '1', ), ]; function sortByDataTypeRecursive(array &$array) { uasort($array, fn($a, $b) => is_array($a) <=> is_array($b)); //asort($array); foreach ($array as &$v) { if (is_array($v)) { (__FUNCTION__)($v); } } } sortByDataTypeRecursive($array); var_export($array);
Output for 7.4.27, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array ( 0 => array ( 'category' => 'Sink', 'lineitem_id' => 'e592feab-1e1a-4cfc-a97a-f1108c7156b6', 'item_number' => '1', 'sublineitems' => array ( 0 => array ( 'quantity' => 1, 'model' => 'PBMS2016-12-X', 'subline_item_id' => '844b7c74-b1b7-4f17-a2da-f0c84cef432d', 'item_type_code' => 0, 'item_type_description' => 'Normal', 'vendor_id' => '4e1ab2ef-774e-4c73-be60-c937d1efeb56', 'customerspecificpricings' => array ( ), 'electricalutilitygrids' => array ( ), 'plumbingutilitygrids' => array ( 0 => array ( 'remarks' => '3-1/2" drain opening', ), ), ), ), ), )

preferences:
59.58 ms | 404 KiB | 63 Q