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;
}
}