3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ //... 'name' => ['value' => 'Raj KB'], 'street' => ['value' => 'Street ABC'], 'city' => ['value' => 'Dubai'], 'country_id' => ['value' => 'UAE'], 'region' => ['value' => 'DXB'], 'region_id' => ['value' => 11], 'zip_code' => ['value' => 12345], 'city_id' => ['value' => 22], //... ]; $ordered_keys = ['country_id' => 256, 'region' => 257, 'region_id' => 258, 'city' => 259, 'city_id' => 260]; $index = 0; $result = []; foreach ($array as $k => $v) { if ( isset($ordered_keys[$k]) ) { $result[$k] = $ordered_keys[$k]; if ( $index < 255 ) $index = 512; } else { $result[$k] = $index++; } } asort($result); foreach($result as $k => $v) { $result[$k] = $array[$k]; } print_r($result);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.14, 8.4.16 - 8.4.18, 8.5.0 - 8.5.3
Array ( [name] => Array ( [value] => Raj KB ) [street] => Array ( [value] => Street ABC ) [country_id] => Array ( [value] => UAE ) [region] => Array ( [value] => DXB ) [region_id] => Array ( [value] => 11 ) [city] => Array ( [value] => Dubai ) [city_id] => Array ( [value] => 22 ) [zip_code] => Array ( [value] => 12345 ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
211.08 ms | 408 KiB | 5 Q