0
如何通过递归将一个数组转换为其他数组?这个例子仅适用于第二级。如何做递归?
$array2 = array();
foreach ($array as $levelKey => $level) {
foreach ($level as $itemKey => $item) {
if (isset($array[$levelKey + 1])) {
$array2[$item['data']['id']] = $item;
$children = $this->searchChildren($item['data']['id'], $array[$levelKey + 1]);
$array += $children;
}
}
}
function searchChildren($parent_id, $level)
{
$_children = array();
foreach ($level as $key => $item) {
if ($item['data']['parent_id'] === $parent_id) {
$_children[$key] = $item;
}
}
return $_children;
}
你必须自己调用你的函数...... – crush 2013-03-07 14:28:56
为了理解递归,你必须了解递归。 – ddinchev 2013-03-07 14:29:08
当你在我的例子中显示它? – tomasr 2013-03-07 14:30:31