Array
(
[0] => Array
(
[id] => 6
[title] => 凤凰
[bid] => 2
)
[1] => Array
(
[id] => 5
[title] => 年康
[bid] => 2
)
[2] => Array
(
[id] => 4
[title] => 海鸥
[bid] => 2
)
[3] => Array
(
[id] => 3
[title] => 111cn.net
[bid] => 1
)
[4] => Array
(
[id] => 2
[title] => 中国WEB第一站
[bid] => 1
)
[5] => Array
(
[id] => 1
[title] => www.111cn.net
[bid] => 1
)
)
//方法一,直接把值取出来,并且输出
foreach($arr as $key=>$val){
foreach($val as $k=>$val2){
if($val2['bid']==1){//判断
echo $val2['bid']."
";
}
}
}
//方法二,把符合条件的数组再次生成数组
代码如下
复制代码
res=array();
foreach($arr as $sub){
foreach($sub as $value){
if($value==1){
array_push($res,$sub);
}
}
}
print_r($res);
//结果为
Array
(
[3] => Array
(
[id] => 3
[title] => 111cn.net
[bid] => 1
)
[4] => Array
(
[id] => 2
[title] => 中国WEB第一站
[bid] => 1
)
[5] => Array
(
[id] => 1
[title] => www.111cn.net
[bid] => 1
)
)
本文原创发布php中文网,转载请注明出处,感谢您的尊重!