3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arr = [ 1 => ["key" => "a"], 2 => ["key" => "b"] ]; foreach ($arr as $key => $val) { $arr[$val["key"]] = $val; unset($arr[$key]); } var_dump($arr);
based on Sjtps
Output for 5.4.0 - 7.2.6
array(2) { ["a"]=> array(1) { ["key"]=> string(1) "a" } ["b"]=> array(1) { ["key"]=> string(1) "b" } }