从多维数组中获取填充的行,其中第一个索引是字符串

时间:2013-11-15 20:35:11

标签: php arrays

我想尝试只通过array_push将填充的行带到另一个数组但是我不能动态地采用它们,因为第一个索引是字符串,我该怎么做呢?感谢。

<?php
 while($i < count($val['error']){

  if($val['error'][$i] === 0)
  {
   array_push($newarray, $val[whatwilliputherebecauseofstringindex][$i]);
  }

 }
?>

Hi here is the pastebin

1 个答案:

答案 0 :(得分:0)

<?php
// get keys of original array (name, type, etc..)
$keys = array_keys($array);
// for each error value ...
foreach ($array['error'] as $key => $val) {
  // if error is not 0..
  if($val !== 0)
  {
    // for each key in the original array.. 
    foreach ($keys as $k) {
      // unset the element of the same iteration
      unset($array[$k][$key]);
    }
  }
}
?>
相关问题