在 php 中从关联数组索引中分离数据
Separating data from an associative array index wise in php
我知道我将为此使用 array_map,但问题一直在说
notice Undefined index: DeviceID.....
我正在尝试将 DeviceID
分隔为 $key
并将其所有值分隔为 $value
//Code
$output = array_map(null,$getTheHistoricData['DeviceID']);
//Array
array (size=4112)
0 =>
array (size=5)
'DeviceID' => string '1' (length=1)
'DeviceTimestamp' => string '2018-09-22 00:00:11' (length=19)
'LineTemp' => string '22.2148' (length=7)
'LineCurrent' => string '232.562' (length=7)
'RxRSSI' => string '0' (length=1)
1 =>
array (size=5)
'DeviceID' => string '1' (length=1)
'DeviceTimestamp' => string '2018-09-22 00:00:33' (length=19)
'LineTemp' => string '22.2154' (length=7)
'LineCurrent' => string '234.672' (length=7)
'RxRSSI' => string '0' (length=1)
2 =>
array (size=5)
'DeviceID' => string '1' (length=1)
'DeviceTimestamp' => string '2018-09-22 00:00:55' (length=19)
'LineTemp' => string '22.2094' (length=7)
'LineCurrent' => string '233.954' (length=7)
'RxRSSI' => string '0' (length=1)
and so on
您应该使用底部所示的 array_map()
来完成这项工作。
$output = array_map(function($val){
return $val['DeviceID'];
}, $getTheHistoricData);
检查结果 demo
你也可以用array_column()
代替
$output = array_column($getTheHistoricData, 'DeviceID');
我知道我将为此使用 array_map,但问题一直在说
notice Undefined index: DeviceID.....
我正在尝试将 DeviceID
分隔为 $key
并将其所有值分隔为 $value
//Code
$output = array_map(null,$getTheHistoricData['DeviceID']);
//Array
array (size=4112)
0 =>
array (size=5)
'DeviceID' => string '1' (length=1)
'DeviceTimestamp' => string '2018-09-22 00:00:11' (length=19)
'LineTemp' => string '22.2148' (length=7)
'LineCurrent' => string '232.562' (length=7)
'RxRSSI' => string '0' (length=1)
1 =>
array (size=5)
'DeviceID' => string '1' (length=1)
'DeviceTimestamp' => string '2018-09-22 00:00:33' (length=19)
'LineTemp' => string '22.2154' (length=7)
'LineCurrent' => string '234.672' (length=7)
'RxRSSI' => string '0' (length=1)
2 =>
array (size=5)
'DeviceID' => string '1' (length=1)
'DeviceTimestamp' => string '2018-09-22 00:00:55' (length=19)
'LineTemp' => string '22.2094' (length=7)
'LineCurrent' => string '233.954' (length=7)
'RxRSSI' => string '0' (length=1)
and so on
您应该使用底部所示的 array_map()
来完成这项工作。
$output = array_map(function($val){
return $val['DeviceID'];
}, $getTheHistoricData);
检查结果 demo
你也可以用array_column()
代替
$output = array_column($getTheHistoricData, 'DeviceID');