我一直试图计算数组中最后一个叶节点元素。我的想法是:
我不知道如何从‘result _ values....or’中获得一个简单的列表数组,我只是得到了一个长串的,有更好的方法来实现这个结果吗?
预期结果:
flammable = 1
irritant = 2
toxic = 3PHP:
$testArray = Array
(
[0] => Array
(
[0] => toxic
[1] => irritant
[3] => flammable
)
[1] => Array
(
[0] => toxic
[1] => irritant
)
[2] => Array
(
[0] => toxic
)
);
array_walk_recursive($testArray, function(&$value)
{
echo 'string = '.$value;
print_r(newArray); //How can i get this new array list?
});
$counts = array_count_values($newArray); //and use this to count values?发布于 2015-11-06 17:13:45
试试这个,数字应该显示在$groups数组中。
$groups = array();
array_walk_recursive($testArray, function(&$value) use (&$groups)
{
if (isset($groups[$value])) {
$groups[$value]++;
} else {
$groups[$value] = 1;
}
});
print_r($groups);https://stackoverflow.com/questions/33572037
复制相似问题