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', 'region', 'region_id', 'city', 'city_id']; $keys = (function ($array, $ordered_keys) { $flag = true; foreach ($array as $key => $v) { if ( $flag && in_array($key, $ordered_keys) ) { yield from $ordered_keys; $flag = false; } yield $key; } })($array, $ordered_keys); $result = []; foreach($keys as $key) { $result[$key] = $array[$key]; } print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
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 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
36.95 ms | 407 KiB | 5 Q