我有两个数组:
$array_1 = [1,2,3,1,2];
以及:
$array_2 = [0,0,0,0,0];
我想更改$array_2
的值,以便仅显示在$array_1
中的元素是数字1或2。
foreach($array_1 as $item)
{
if($item = 1 || $iten == 2)
{
$index = ...;//how to get index of this element
$array_2[$index] = 1; //I don't sure this syntax is right
}
}
输出$array_2
应该是这样的:$array_2 = [1,1,0,1,1]