如何去除一些数据(数组)


   
  array (
  
'cid' => '9',
'pid' => '1',
),
2 =>
array (
'cid' => '8',
'pid' => '1',
),
3 =>
array (
'cid' => '6',
'pid' => '1',
),
4 =>
array (
'cid' => '4',
'pid' => '1',
),
5 =>
array (
'cid' => '11',
'pid' => '1',
),
),
2 =>
array (
0 =>
array (
'cid' => '7',
'pid' => '2',
),
),
3 =>
array (
0 =>
array (
'cid' => '5',
'pid' => '3',
),
),
)

大家看这个数组,我用下面的方法,将cid号取出来。

   
  foreach($data as $k=>$v){
  
$c[$k]=$v;
foreach($c[$k] as $d){
$cids[]=$d['cid'];
}
}

得到结果为

   
  array (
  
0 => '1',
1 => '2',
2 => '3',
3 => '10',
4 => '9',
5 => '8',
6 => '6',
7 => '4',
8 => '11',
9 => '7',
10 => '5',
)

这是取出所有的cid号,不过我不想要pid=0的数据,也就是说如何只取出pid!=0的cid号,谢谢!!

php 数组

yohyoh 11 years, 3 months ago

Your Answer