$a=array([0]=>0 [1]=>3)
$b=array([0]=>image [1]=>profile [2]=>password [3]=>login)
我想數組的鍵值即0比較數組b中的索引值數組0
$a=array([0]=>0 [1]=>3)
$b=array([0]=>image [1]=>profile [2]=>password [3]=>login)
我想數組的鍵值即0比較數組b中的索引值數組0
使用此
$a = array(0, 3);
$b = array(0 => 'image', 1 => 'profile', 2 => 'password', 3 => 'login');
$c = array_intersect_key($b, array_flip($a));
結果
Array
(
[0] => image
[3] => login
)
array_intersect($a,$b);
或嘗試===
運營商比較值在陣列中
<?php
$a=array(0,3);
$b=array(image,password);
foreach($a as $k=>$v){
if($a[$k]===$b[$k]){
echo "$k index is Same<br>";
}else{
echo "$k index is different<br>";
}
}
輸出
0 index is different
1 index is different
使用inarray到的foreach
<?php
$a = array(0,3);
$b= array('image','profile','password','login');
foreach($b as $key=>$value){
if(in_array($key, $a)) {
echo $value."<br>";
}
}
?>
輸出
image
login