Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中显示仅满足此条件的数组_Php_Arrays_Sorting_Php 5.3 - Fatal编程技术网

在php中显示仅满足此条件的数组

在php中显示仅满足此条件的数组,php,arrays,sorting,php-5.3,Php,Arrays,Sorting,Php 5.3,我有一个多维数组,iam在其中循环以获得子数组: 我有一个子数组,它是: array ( 0 => array ( 'norm_value' => 2.5, ), 1 => array ( 'norm_value' => 7.01, ), 2 => array ( 'norm_value' => 0.0, ), 3 => array ( 'norm_value' =>

我有一个多维数组,iam在其中循环以获得子数组: 我有一个子数组,它是:

array (
  0 => 
  array (
    'norm_value' => 2.5,
  ),
  1 => 
  array (
    'norm_value' => 7.01,
  ),
  2 => 
  array (
    'norm_value' => 0.0,
  ),
  3 => 
  array (
    'norm_value' => 4.167,
  ),
  4 => 
  array (
    'norm_value' => 0.0,
  ),
)

array (
  0 => 
  array (
    'norm_value' => 0.0,
  ),
  1 => 
  array (
    'norm_value' => 0.0,
  ),
  2 => 
  array (
    'norm_value' => 0.0,
  ),
  3 => 
  array (
    'norm_value' => 1.267,
  ),
  4 => 
  array (
    'norm_value' => 0.0,
  ),
)

array (
  0 => 
  array (
    'norm_value' => 0.0,
  ),
  1 => 
  array (
    'norm_value' => 0.0,
  ),
  2 => 
  array (
    'norm_value' => 0.0,
  ),
  3 => 
  array (
    'norm_value' => 0.0,
  ),
  4 => 
  array (
    'norm_value' => 0.0,
  ),
)

array (
  0 => 
  array (
    'norm_value' => 3.54,
  ),
  1 => 
  array (
    'norm_value' => 2.04,
  ),
  2 => 
  array (
    'norm_value' => 0.673,
  ),
  3 => 
  array (
    'norm_value' => 8.546,
  ),
  4 => 
  array (
    'norm_value' => 0.0,
  ),
)
因此,从上面的数组集合中,我想删除至少有一个非零值或所有零值的完整数组,从上面的例子中,我想删除完整的第二个数组(这只有一个非零值)和第三个数组(这有所有零值)数组,其他两个(第一个和最后一个)数组将按原样显示

我尝试了这个代码派,但对我无效:

array_filter(array_column($array, 'norm_value'),function($n){
    return ( count ($n > 0) <= 1) ;
});
array\u过滤器(array\u列($array,'norm\u value'),函数($n){

return(count($n>0)我们将循环每个子数组,并计算有多少
norm_值
0.0
。如果计数与
size
size-1
匹配,则我们取消设置该索引

$epsilon = 0.00001;

foreach($arr as $index => $subarray){
    $count = 0;
    foreach($subarray as $norm_data){
        if(abs($norm_data['norm_value'] - 0.0) < $epsilon) $count++;
    }

    if($count === count($subarray) || $count == count($subarray)-1){
        unset($arr[$index]);
    }
}

print_r($arr);
$epsilon=0.00001;
foreach($arr作为$index=>$subarray){
$count=0;
foreach($norm_data作为子数组){
如果(abs($norm_data['norm_value']-0.0)<$epsilon)$count++;
}
如果($count==count($subarray)|$count==count($subarray)-1){
未结算($arr[$index]);
}
}
印刷费($arr);

演示:

你能分享你数组的var_export()吗?@vivek_23,这是var_export()后的数据:链接给我一条文件未找到的消息。你能通过编辑在帖子中发布var_export()吗?@vivek_23已经用var_export()数据编辑了帖子结果,你是对的