我如何做php数组的汇总值?
我想显示这样的结果。
DEVICE_1:LOW = 1,MEDIUM = 0,HIGHT = 0;
DEVICE_2:LOW = 2,MEDIUM = 0,HIGHT = 0;
DEVICE_3:LOW = 0,MEDIUM = 1,HIGHT = 2;
这是我的业务api服务的一些数据
Array
(
[0] => Array
(
[0] => DEVICE_1
[1] => LOW
[2] => STAGE_1
)
[1] => Array
(
[0] => DEVICE_2
[1] => LOW
[2] => STAGE_1
)
[2] => Array
(
[0] => DEVICE_2
[1] => LOW
[2] => STAGE_2
)
[3] => Array
(
[0] => DEVICE_3
[1] => MEDIUM
[2] => STAGE_1
)
[4] => Array
(
[0] => DEVICE_3
[1] => HIGHT
[2] => STAGE_2
)
[5] => Array
(
[0] => DEVICE_3
[1] => HIGHT
[2] => STAGE_3
)
)
答案 0 :(得分:0)
你在哪里得到映射,例如LOW = 1?
在内循环中用你的映射替换。
foreach ( $array as $device ) {
$deviceInfo = '';
foreach ( $device as $specs ) {
$deviceInfo .= $specs . ' ';
}
echo $deviceInfo;
}