3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arX = Array('AAA' => 173.696, 'BBB' => 72.436, 'CCC' => 142.692); $arY = Array('AAA' => 127, 'DDD' => 72.333); $newArray = []; $callback = function($value, $key , $prefix) use (&$newArray) { if (!array_key_exists ($key , $newArray)) { $newArray[$key] = []; } $newArray[$key] += [$prefix => $value]; }; array_walk($arX , $callback , "X"); array_walk($arY , $callback , "Y"); var_dump($newArray);

preferences:
23.55 ms | 405 KiB | 5 Q