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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
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:
91.02 ms | 407 KiB | 5 Q