3v4l.org

run code in 300+ PHP versions simultaneously
<?php $structure = [ "a", "b" => [ "b1", "b2" => [ "b21", "b22" ] ] ]; $data = ['A', 'B1', 'B21', 'B22']; function alterKey(&$arr, $data) { foreach ($arr as $key => $val) { if (!is_array($val)) { $data_key = array_search(strtoupper($val), $data); $arr[$val] = $data[$data_key]; unset($arr[$key]); } else { $arr[$key] = alterKey($val, $data); } } ksort($arr); return $arr; } alterKey($structure, $data); echo '<pre>', print_r($structure);
Output for git.master, git.master_jit, rfc.property-hooks
<pre>Array ( [a] => A [b] => Array ( [b1] => B1 [b2] => Array ( [b21] => B21 [b22] => B22 ) ) ) 1

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:
46.32 ms | 401 KiB | 8 Q