How I do summary value of php array ?
I want to display result like this.
DEVICE_1 : LOW=1,MEDIUM=0,HIGHT=0;
DEVICE_2 : LOW=2,MEDIUM=0,HIGHT=0;
DEVICE_3 : LOW=0,MEDIUM=1,HIGHT=2;
如何计算php数组的摘要值?我想显示这样的结果。DEVICE_1:低= 1,中等= 0,高= 0;DEVICE_2:低= 2,中等= 0,高= 0;DEVICE_3:低= 0,中等= 1,高= 2;
This is some data from my business api service
这是来自我的业务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
)
)
1 个解决方案
#1
0
Where are you getting the mappings such as LOW = 1?
Replace in the inner loop with your mappings.
在哪里得到映射,比如LOW = 1?用映射替换内部循环。
foreach ( $array as $device ) {
$deviceInfo = '';
foreach ( $device as $specs ) {
$deviceInfo .= $specs . ' ';
}
echo $deviceInfo;
}
#1
0
Where are you getting the mappings such as LOW = 1?
Replace in the inner loop with your mappings.
在哪里得到映射,比如LOW = 1?用映射替换内部循环。
foreach ( $array as $device ) {
$deviceInfo = '';
foreach ( $device as $specs ) {
$deviceInfo .= $specs . ' ';
}
echo $deviceInfo;
}