时间:2021-07-01 10:21:17 帮助过:2人阅读
$array1=array("1","2","3","4","5","6");//此数据值固定。
$array2=array("1","3","6","4");//此数据值不固定。
$arr = array();
$x;
foreach($array2 as $k => $v) {
x = array_search($v,$array1);
if (x) {
$arr[$k] = $v;
} else {
$arr[$k] = 0;
}
}
$array1=array("1","2","3","4","5","6");//此数据值固定。
$array2=array("1","3","6","4");//此数据值不固定。
$arr = array();
foreach($array1 as $v){
$arr[] = in_array($v, $array2) ? $v : 0;
}
print_r($arr);
$a = array("1","2","3","4","5","6");
$b = array("1","3","6","4");
$c = $a;
foreach(array_diff($a, $b) as $k=>$v) $c[$k] = 0;
print_r($c);
Array
(
[0] => 1
[1] => 0
[2] => 3
[3] => 4
[4] => 0
[5] => 6
)
$array1=array("1","2","3","4","5","6");//此数据值固定。
$array2=array("1","3","6","4");//此数据值不固定。
$c = array_diff($array1, $array2);
foreach($c as $k=>$v){
$array1[$k] = 0;
}
print_r($array1);