Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 - Fatal编程技术网

Php 数组-删除值为零的记录

Php 数组-删除值为零的记录,php,arrays,Php,Arrays,我得到了一个数组,我想删除[quantity]=>0的所有记录 Array ( [0] => Array ( [id] => 1 [is_sub] => 0 [product] => Town [quantity] => 0 [price] => [total_item_price] => 0 [comments] => ) [1] => Array ( [id] => 3 [is_sub] => 0 [product

我得到了一个数组,我想删除[quantity]=>0的所有记录

 Array ( 
 [0] => Array ( [id] => 1 [is_sub] => 0 [product] => Town [quantity] => 0 [price] => [total_item_price] => 0 [comments] => ) 

 [1] => Array ( [id] => 3 [is_sub] => 0 [product] => City [quantity] => 0 [price] => [total_item_price] => 0 [comments] => ) 
 )

 [2] => Array ( [id] => 3 [is_sub] => 0 [product] => News [quantity] => 1 [price] => [total_item_price] => 0 [comments] => ) 
 )
谢谢你的帮助

我猜是PHP

你可以做:

foreach($arr as $key => $value) {
    if($value['quantity'] < 1) {
        unset($arr[$key]);
    }
}

使用
阵列过滤器

$array = array_filter($array, function($x) {
    return $x['quantity'] != 0;
});

你用哪种语言?到目前为止,你尝试了什么?告诉我们你正在使用哪种语言。这看起来像PHP<代码> PrimtTyr()/Case>格式。考虑使用它从IDS=$$会话[OnLanguIId ]获取的值。我想删除与数量0匹配的记录。它还需要重新索引数组以使其长度为实际长度<代码>$arr=数组_值($arr)
$array = array_filter($array, function($x) {
    return $x['quantity'] != 0;
});