php json去除多余字段,如何在PHP [laravel]中從JSON多數組中移除字段

I`m scratching my head all day and cant figure out. Can someone help me please.

我整天都在撓頭,弄不明白。有人能幫我嗎?

I need to make that if all values is null in same column then do not show date and those fields with NULL.

如果所有值在同一列中為null,那么就不要顯示日期和空值字段。

In below example need to remove 2015-09-17 value becouse log1, log2, log3, log4, log5 has empty values in 5 position of that field.

在以下示例中,需要刪除2015-09-17的值becouse log1、log2、log3、log4、log5在該字段的5個位置上都有空值。

0 - column - "2015-09-12"

1 - column - "2015-09-13"

2 - column - "2015-09-14"

3 - column - "2015-09-15"

4 - column - "2015-09-16"

5 - column - "2015-09-17"

6 - column - "2015-09-18"

{

"error": false,

"stats": {

"x": [

"2015-09-12",

"2015-09-13",

"2015-09-14",

"2015-09-15",

"2015-09-16",

"2015-09-17",

"2015-09-18"

],

"log1": [

null,

null,

null,

null,

null,

null,

null

],

"log2": [

"3.0000",

null,

null,

"0.0000",

"0.7500",

null,

"3.0000"

],

"log3": [

null,

null,

null,

"200",

null,

null,

null

],

"log4": [

1,

null,

null,

5,

4,

null,

2

],

"log5": [

null,

null,

null,

null,

null,

null,

null

]

}

}

1 个解决方案

#1

0

Fixed problem by using this function:

固定問題使用此功能:

private function array_intersect_by_key_position($model)

{

$result_array = array_intersect_assoc($model['log1'], $model['log2'], $model['log3'], $model['log4'], $model['log5']);

//dd($result_array);

if(count($result_array) > 0)

{

foreach($result_array as $res => $val)

{

unset($model['x'][$res]);

unset($model['log1'][$res]);

unset($model['log2'][$res]);

unset($model['log3'][$res]);

unset($model['log4'][$res]);

unset($model['log5'][$res]);

}

$model['x'] = array_values($model['x']);

$model['log1'] = array_values($model['log1']);

$model['log2'] = array_values($model['log2']);

$model['log3'] = array_values($model['log3']);

$model['log4'] = array_values($model['log4']);

$model['log5'] = array_values($model['log5']);

return $model;

}

else

{

return $model;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值