Php 数组-删除值为零的记录
我得到了一个数组,我想删除[quantity]=>0的所有记录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
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;
});