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.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(5) { ["James"]=> string(5) "Green" ["Mike"]=> string(4) "Blue" ["Liam"]=> string(6) "Yellow" ["Shantel"]=> string(6) "Purple" ["Harry"]=> string(3) "Red" }

preferences:
122.08 ms | 402 KiB | 121 Q