php如何条件判断筛选数组数据 20

array0=>array'id'=>string'76'(length=2)'title'=>string'gf'(length=2)'type'=>string'4'... array
0 =>
array
'id' => string '76' (length=2)
'title' => string 'gf' (length=2)
'type' => string '4' (length=1)
'update_time' => string '1433814812' (length=10)
'status' => string '1' (length=1)
'view' => string '0' (length=1)
'category_id' => string '2' (length=1)
'model_id' => string '2' (length=1)
'pid' => string '0' (length=1)
1 =>
array
'id' => string '75' (length=2)
'title' => string '骑士妙招破死局' (length=21)
'type' => string '1' (length=1)
'update_time' => string '1433758503' (length=10)
'status' => string '1' (length=1)
'view' => string '0' (length=1)
'category_id' => string '2' (length=1)
'model_id' => string '2' (length=1)
'pid' => string '0' (length=1)
2 =>
array
'id' => string '74' (length=2)
'title' => string '职场新人要学会的4件事' (length=31)
'type' => string '5' (length=1)
'update_time' => string '1433757936' (length=10)
'status' => string '1' (length=1)
'view' => string '0' (length=1)
'category_id' => string '2' (length=1)
'model_id' => string '2' (length=1)
'pid' => string '0' (length=1)
3 =>
array
'id' => string '73' (length=2)
'title' => string '职场新人该如何看待繁琐的工作' (length=42)
'type' => string '5' (length=1)
'update_time' => string '1433757902' (length=10)
'status' => string '0' (length=1)
'view' => string '0' (length=1)
'category_id' => string '2' (length=1)
'model_id' => string '2' (length=1)
'pid' => string '0' (length=1)
数组的数据类型是上面这样的,我想根据type的值筛选出数据,比如type=4,那么久只要所有type=4的数据,请问用PHP怎么写?
展开
 我来答
匿名用户
推荐于2017-05-19
展开全部
<?php

$a = array(
'BL001'=>array('A14257','B17548'),
'CDF002'=>array('A14257','C48751'),
'FGE453'=>array('DF5533','GR6445','GH5544'),
'GEN001'=>array('NT7532','DE9342','C48751'),
);

$b = array('A14257','E453T4','Y64344','FG4809','C48751','H4443R');

foreach($a as $k=>$v){
$t = array_intersect ($v, $b);
if($t){
$c[$k] = $t;
}
}

print_r($c);
?>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
captain2005
2015-06-10 · TA获得超过1059个赞
知道小有建树答主
回答量:2041
采纳率:40%
帮助的人:568万
展开全部
<?php
$res=array (
0 => array('id' =>'76',
'title' =>'gf',
'type' =>'4' ,
'update_time' =>'1433814812',
'status' =>'1' ,
'view' =>'0',
'category_id' =>'2' ,
'model_id' =>'2',
'pid' =>'0'),
1 => array('id' =>'75',
'title' =>'骑士妙招破死局' ,
'type' =>'1',
'update_time' =>'1433758503',
'status' =>'1' ,
'view' =>'0' ,
'category_id' =>'2',
'model_id' =>'2',
'pid' =>'0'),
2 =>array('id' =>'74',
'title' =>'职场新人要学会的4件事',
'type' =>'5',
'update_time' =>'1433757936',
'status' =>'1',
'view' =>'0',
'category_id' =>'2',
'model_id' =>'2',
'pid' =>'0'),
3 =>array('id' =>'73',
'title' =>'职场新人该如何看待繁琐的工作',
'type' =>'5',
'update_time' =>'1433757902',
'status' =>'0',
'view' =>'0',
'category_id' =>'2',
'model_id' =>'2',
'pid' =>'0'));
$tot=count($res);
for($i=0;$i<$tot;$i++)
{
if($res[$i]['type']=='5')
{
foreach($res[$i] as $a)
{
echo("<div>".$a."</div>");
}
}
}
?>
追问
数据格式还是要和原来的一样
你的没有
追答
php本来就是一个数据类型转换功能很强的语言,它有很强的类型隐式转换的功能
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式