3v4l.org

run code in 300+ PHP versions simultaneously
<?php $customer['address'] = '123 fake st'; $customer['name'] = 'Tim'; $customer['dob'] = '12/08/1986'; $customer['dontSortMe'] = 'this value doesnt need to be sorted'; $order = array('name', 'dob', 'address'); $keys= array_flip($order); uksort($customer, function($a, $b)use($keys){ return $keys[$a] - $keys[$b]; }); print_r($customer);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Warning: Undefined array key "dontSortMe" in /in/Q4osh on line 12 Warning: Undefined array key "dontSortMe" in /in/Q4osh on line 12 Warning: Undefined array key "dontSortMe" in /in/Q4osh on line 12 Array ( [name] => Tim [dontSortMe] => this value doesnt need to be sorted [dob] => 12/08/1986 [address] => 123 fake st )

preferences:
73.76 ms | 403 KiB | 91 Q