关键是array_filter这个函数;例子: 原数组:
Array
(
[0] => Array
(
[ExchangeNo] => ECR000033
[CardNo] => Array
(
)
[QTY] => 1
[ExchangeDate] => 2013-06-13T18:55:23.84
[Remark] => Array
(
)
)
[1] => Array
(
[ExchangeNo] => ECR000036
[CardNo] => Array
(
)
[QTY] => 20
[ExchangeDate] => 2013-06-20T18:24:32.53
[Remark] => Array
(
)
)
[2] => Array
(
[ExchangeNo] => ECR000037
[CardNo] => Array
(
)
[QTY] => 20
[ExchangeDate] => 2013-06-20T18:28:23.14
[Remark] => Array
(
)
)
[3] => Array
(
[ExchangeNo] => ECR000038
[CardNo] => Array
(
)
[QTY] => 20
[ExchangeDate] => 2013-06-20T18:30:53.71
[Remark] => Array
(
)
)
)
去除空数组:
foreach ($array as $key=>$value){
$array[$key] = array_filter($value);
}
输出结果:
Array
(
[0] => Array
(
[ExchangeNo] => ECR000033
[QTY] => 1
[ExchangeDate] => 2013-06-13T18:55:23.84
)
[1] => Array
(
[ExchangeNo] => ECR000036
[QTY] => 20
[ExchangeDate] => 2013-06-20T18:24:32.53
)
[2] => Array
(
[ExchangeNo] => ECR000037
[QTY] => 20
[ExchangeDate] => 2013-06-20T18:28:23.14
)
[3] => Array
(
[ExchangeNo] => ECR000038
[QTY] => 20
[ExchangeDate] => 2013-06-20T18:30:53.71
)
)
- 原文作者: forecho
- 原文链接: https://blog.forecho.com/php-qu-chu-er-wei-shu-zu-zhong-de-kong-shu-zu.html
- 版权声明:本作品采用 署名-非商业性使用 4.0 国际 (CC BY-NC 4.0)进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。