3v4l.org

run code in 300+ PHP versions simultaneously
<?php $final = array(); $names = ['James', 'Mike', 'Liam', 'Shantel', 'Harry']; $colors = ['Green', 'Blue', 'Yellow', 'Purple', 'Red']; foreach($names as $i => $key) { $final[$key] = $colors[$i]; } var_dump($final);
Output for 7.4.0 - 7.4.30, 8.0.1 - 8.0.20, 8.1.0 - 8.1.7
array(5) { ["James"]=> string(5) "Green" ["Mike"]=> string(4) "Blue" ["Liam"]=> string(6) "Yellow" ["Shantel"]=> string(6) "Purple" ["Harry"]=> string(3) "Red" }

preferences:
28.67 ms | 409 KiB | 5 Q