PHP で交差多次元配列をループし、その ID と PID (親キー ID) を与える方法
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> 配列(7) { [1] => 配列(5) { ["id"] => 文字列(1) "1" ["pid"] => 文字列(1) "0" ["名前"] => string(15) "資産管理" ["タイトル"] => string(12) "資産管理" ["サブメニュー"] => 配列(1) { [0] => 文字列(0) "" } } [2] => 配列(5) { ["id"] => 文字列(1) "2" ["pid"] => 文字列(1) "0" ["名前"] => 文字列(14) "システム設定" ["タイトル"] => string(12) "システム設定" ["サブメニュー"] => 配列(1) { [0] => 文字列(0) "" } } [3] => 配列(5) { ["id"] => 文字列(1) "3" ["pid"] => 文字列(1) "0" ["名前"] => string(19) "管理" ["タイトル"] => string(12) "バックエンド管理" ["サブメニュー"] => 配列(1) { [0] => 文字列(0) "" } } [4] => 配列(5) { ["id"] => 文字列(2) "11" ["pid"] => 文字列(1) "1" ["名前"] => 文字列(9) "HZ" ["タイトル"] => 文字列(15) "HZ" ["サブメニュー"] => 配列(1) { [0] => 文字列(0) "" } } [5] => 配列(5) { ["id"] => 文字列(2) "10" ["pid"] => 文字列(1) "1" ["名前"] => 文字列(9) "XM" ["タイトル"] => 文字列(15) "XM" ["サブメニュー"] => 配列(1) { [0] => 文字列(0) "" } } [6] => 配列(5) { ["id"] => 文字列(1) "9" ["pid"] => 文字列(1) "1" ["名前"] => string(9) "BJ" ["タイトル"] => 文字列(15) "BJ" ["サブメニュー"] => 配列(1) { [0] => 文字列(0) "" } } [7] => 配列(5) { ["id"] => 文字列(1) "4" ["pid"] => 文字列(1) "1" ["名前"] => string(20) "トータル管理" ["タイトル"] => string(15) "一般管理" ["サブメニュー"] => 配列(3) { [0] => 配列(5) { ["id"] => 文字列(1) "5" ["名前"] => string(12) "PC" ["メニューID"] => 文字列(1) "4" ["タイトル"] => 文字列(17) "PC" ["アクセス"] => int(1) } [1] => 配列(5) { ["id"] => 文字列(1) "6" ["名前"] => 文字列(13) "BJB" ["メニューID"] => 文字列(1) "4" ["タイトル"] => 文字列(18) "BJB" ["アクセス"] => int(1) } [2] => 配列(5) { ["id"] => 文字列(1) "7" ["名前"] => string(16) "選択" ["メニューID"] => 文字列(1) "4" ["タイトル"] => 文字列(15) "クエリ" ["アクセス"] => int(1) } } } } 上記の配列を以下のように書くにはどうすればよいでしょうか?配列(3) { [1] =>配列(5) { ["id"] =>文字列(1) "1" ["pid"] =>文字列(1) "0" ["名前"] => string(15) "資産管理" ["タイトル"] => string(12) "资产管理" ["サブメニュー"] =>配列(4) { [1] =>配列(5) { ["id"] =>文字列(2) "11" ["pid"] =>文字列(1) "1" ["名前"] =>文字列(9) "HZ" ["タイトル"] =>文字列(15) "HZ" ["サブメニュー"] =>配列(1) { [0] =>文字列(0) "" } } [2] =>配列(5) { ["id"] =>文字列(2) "10" ["pid"] =>文字列(1) "1" ["名前"] =>文字列(9) "XM" ["タイトル"] =>文字列(15) "XM" ["サブメニュー"] =>配列(1) { [0] =>文字列(0) "" } } [3] =>配列(5) { ["id"] =>文字列(1) "9" ["pid"] =>文字列(1) "1" ["名前"] =>文字列(9) "BJ" ["タイトル"] =>文字列(15) "BJ" ["サブメニュー"] =>配列(1) { [0] =>文字列(0) "" } } [4] =>配列(5) { ["id"] =>文字列(1) "4" ["pid"] =>文字列(1) "1" ["名前"] => string(20) "トータルマネジメント" ["タイトル"] => string(15) "总管理" ["サブメニュー"] =>配列(3) { [0] =>配列(5) { ["id"] =>文字列(1) "5" ["名前"] =>文字列(12) "PC" ["メニューID"] =>文字列(1) "4" ["タイトル"] =>文字列(17) "PC" ["アクセス"] => int(1) } [1] =>配列(5) { ["id"] =>文字列(1) "6" ["名前"] =>文字列(13) "BJB" ["メニューID"] =>文字列(1) "4" ["タイトル"] =>文字列(18) "BJB" ["アクセス"] => int(1) } [2] =>配列(5) { ["id"] =>文字列(1) "7" ["名前"] => string(16) "選択" ["メニューID"] =>文字列(1) "4" ["タイトル"] => string(15) "查询" ["アクセス"] => int(1) } } } } } [2] =>配列(5) { ["id"] =>文字列(1) "2" ["pid"] =>文字列(1) "0" ["名前"] =>文字列(14) "システム設定" ["タイトル"] => string(12) "システム统设置" ["サブメニュー"] =>配列(1) { [0] =>文字列(0) "" } } [3] =>配列(5) { ["id"] =>文字列(1) "3" ["pid"] =>文字列(1) "0" ["名前"] => string(19) "管理" ["タイトル"] => string(12) "后台管理" ["サブメニュー"] =>配列(1) { [0] =>文字列(0) "" } } } <div class="clear"></div>