php 判断二维数组里面是否有相同的值
1个回答
推荐于2016-11-12 · 知道合伙人数码行家
关注
展开全部
方法一:
$user = array("ID"=>array( "0","1","2"),"Day"=>array("5")); //二维数组
$arrID = $user["ID"];
$str = "2"; //要判断的值
foreach ($arrID as $value){ //遍历数组arrID
if ($str == $value){ //如果要判断的值在数组中,则退出
echo "$str in array";
break;
}
}
方法二:
$user = array("ID"=>array( "0","1","2"),"Day"=>array("5")); //二维数组
$str = "1"; //要判断的值
foreach ($user as $key => $arrKey){ //遍历二维数组
if ($key =="ID" ){ //如果Key=ID
foreach ( $arrKey as $value){//遍历key=ID的数组,在遍历前还可以加一个是否为数组的判断
if ($value == $str){ //如果要判断的值在数组中,则退出
echo "$str is in the array";
break;
}
}
}
}
$user = array("ID"=>array( "0","1","2"),"Day"=>array("5")); //二维数组
$arrID = $user["ID"];
$str = "2"; //要判断的值
foreach ($arrID as $value){ //遍历数组arrID
if ($str == $value){ //如果要判断的值在数组中,则退出
echo "$str in array";
break;
}
}
方法二:
$user = array("ID"=>array( "0","1","2"),"Day"=>array("5")); //二维数组
$str = "1"; //要判断的值
foreach ($user as $key => $arrKey){ //遍历二维数组
if ($key =="ID" ){ //如果Key=ID
foreach ( $arrKey as $value){//遍历key=ID的数组,在遍历前还可以加一个是否为数组的判断
if ($value == $str){ //如果要判断的值在数组中,则退出
echo "$str is in the array";
break;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询