ツリー配列を普通の二次元配列に変換する方法を教えてください
この構造であれば要素の順番は関係ありません
例えば
Array
(
[0] => ; array
)[Kind_id] => 1110
[kind_fid] => )
)
)
)
[2] => 配列
(
[kind_id] => 1107
[kind_fid] => 1101
[kind_name] => aaaaaaaa
[子] => 配列
(
)
)
转である
配列
(
[0] => 配列
(
[kind_id] => 1103
[kind_fid] => 1101
[種類名] =>asdfsadf
)
[1] => 配列
(
[kind_id] => 1109
[kind_fid] =>1103
[kind_name] => asdfsadf
[2] =>配列
(
[kind_id] => 1104
[kind_fid] => ; 1101
[kind_name] => asdfsadf )
[3] => 配列
[kind_id] => 110
[kind_fid] => 1104
[kind_name] => asdfsadf
[ 4] => 配列 (
[kind_id] => 1107
[kind_fid] => 1101
[種類名] => asdfsadf
)
)
$ar = array ( 0 => array ( 'kind_id' => '1103', 'kind_fid' => '1101', 'kind_name' => 'asdfsadf', 'children' => array ( 0 => array ( 'kind_id' => '1109', 'kind_fid' => '1103', 'kind_name' => 'testt', 'children' => array ( ), ), ), ), 1 => array ( 'kind_id' => '1104', 'kind_fid' => '1101', 'kind_name' => 'sdfsdf', 'children' => array ( 0 => array ( 'kind_id' => '1110', 'kind_fid' => '1104', 'kind_name' => 'test222', 'children' => array ( ), ), ), ), 2 => array ( 'kind_id' => '1107', 'kind_fid' => '1101', 'kind_name' => 'aaaaaaaa', 'children' => array ( ), ),);print_r(untree($ar));function untree($ar) { $res = array(); foreach($ar as $v) { $t = $v['children']; unset($v['children']); $res[] = $v; if($t) $res = array_merge($res, untree($t)); } return $res;}