3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = ['0' => '1', '1' => '2', '2' => '3', '3' => '4']; $array2 = ['0' => '3', '1' => '1']; foreach ($array1 as $k => $v) { if (in_array($v, $array2)) $array1[$k] = 0; } print_r($array1);
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13, 8.1rc1 - rc3
Array ( [0] => 0 [1] => 2 [2] => 0 [3] => 4 )

preferences:
60.93 ms | 533 KiB | 14 Q