phparray_sum多维数组我想得到每个数组的字母的和。请看一下我的代码
阵列(/----------------帮助---------/
[0] => Array
(
[0] => Array
(
[a] => 1
[b] => 0
[c] => 0
[d] => 0
)
[1] => Array
(
[a] => 0
[b] => 1
[c] => 0
[d] => 0
)
)
[1] => Array
(
[0] => Array
(
[a] => 1
[b] => 0
[c] => 0
[d] => 0
)
[1] => Array
(
[a] => 0
[b] => 1
[c] => 0
[d] => 0
)
)
)每个数组的总和想要这样的结果请帮助
[0] => Array
(
[a] => 2
[b] => 0
[c] => 0
[d] => 0
)
[1] => Array
(
[a] => 0
[b] => 2
[c] => 0
[d] => 0
)
需要帮助
在没有任何标签的情况下,我用PHP
来解释,因为这是我直觉中的样子:(
一旦我知道你的语言支持,我一定会编辑我的帖子。
<?php
$myarr = Array(
0 => Array
(
'a' => 1,
'b' => 0,
'c' => 0,
'd' => 0,
),
1=> Array
(
'a' => 0,
'b' => 1,
'c' => 0,
'd' => 0,
),
2 => Array
(
'a' => 0,
'b' => 0,
'c' => 1,
'd' => 0,
),
);
foreach($myarr as &$qwe )
{
foreach($qwe as $key => &$value)
{
if($value == 1 )
$value++;
}
}
print_r($myarr);
输出
Array
(
[0] => Array
(
[a] => 2
[b] => 0
[c] => 0
[d] => 0
)
[1] => Array
(
[a] => 0
[b] => 2
[c] => 0
[d] => 0
)
[2] => Array
(
[a] => 0
[b] => 0
[c] => 2
[d] => 0
)
)