How does php traverse cross-dimensional arrays and give their id and pid (parent key id) PHPcodearray (7) {[1] & gt; array (5) {[& quot; id & quot;] & gt; string (1) & quot; 1 & quot; [& quot; pid & quot;] & gt; string (1) & quot; 0 & quot; how does php traverse cross-dimensional arrays and give their id and pid (parent key id)
PHP code
Array (7) {[1] => array (5) {["id"] => string (1) "1" ["pid"] => string (1) "0" ["name"] => string (15) "AssetManagement" ["title"] => string (12) "Asset management" ["submenu"] => array (1) {[0] => string (0) ""} [2] => array (5) {["id"] => string (1) "2" ["pid"] => string (1) "0" ["name"] => string (14) "SystemSettings" ["title"] => string (12) "system settings" ["submenu"] => array (1) {[0] => string (0) ""} [3] => array (5) {["id"] => string (1) "3" ["pid"] => string (1) "0" ["name"] => string (19) "Management" ["title"] => string (12) "Background management" ["submenu"] => array (1) {[0] => string (0) ""} [4] => array (5) {["id"] => string (2) "11" ["pid"] => string (1) "1" ["name"] => string (9) "HZ" ["title"] => string (15) "HZ" ["submenu"] => array (1) {[0] => string (0) ""} [5] => array (5) {["id"] => string (2) "10" ["pid"] => s Tring (1) "1" ["name"] => string (9) "XM" ["title"] => string (15) "XM" ["submenu"] => array (1) {[0] => string (0) ""} [6] => array (5) {["id"] => string (1) "9" ["pid"] => string (1) "1" ["name"] => string (9) "BJ" ["title"] => string (15) "BJ" ["submenu"] => array (1) {[0] => string (0) ""} [7] => array (5) {["id"] => string (1) "4" ["pid"] => string (1) "1" ["name"] => string (20) "TotalManagement" ["Title"] => string (15) "Total management" ["submenu"] => array (3) {[0] => array (5) {["id"] => string (1) "5" ["name"] => string (12) "PC" ["menu_id"] => string (1) "4" ["title"] => string (17) "PC" ["access"] => int (1)} [1] => array (5) {["id"] => string (1) "6" ["name"] => string (13) "BJB" ["menu_id"] => string (1) "4" ["title"] => string (18) "BJB" ["access"] => int (1)} [2] => array (5) {["id"] => string (1) "7 "[" Name "] => string (16)" Select "[" menu_id "] => string (1)" 4 "[" title "] => string (15) "query" ["access"] => int (1) }}} how to write the above array as below? Array (3) {[1] => array (5) {["id"] => string (1) "1" ["pid"] => string (1) "0" ["name"] => string (15) "AssetManagement" ["title"] => string (12) "Asset management" ["submenu"] => array (4) {[1] => array (5) {["id"] => string (2) "11" ["pid"] => string (1) "1" ["name"] => string (9) "HZ" ["title"] => string (15) "HZ" ["submenu"] => array (1) {[0] => string (0) ""} [2] => array (5) {["id"] => string (2) "10" ["pid"] => string (1) "1" ["name"] => string (9) "XM" ["title"] => string (15) "XM" ["submenu"] => array (1) {[0] => string (0) ""} [3] => array (5) {["id"] => string (1) "9" ["pid"] => string (1) "1" ["name"] => string (9) "BJ" ["title"] => string (15) "BJ" ["submenu"] => array (1) {[0] => string (0) ""} [4] => array (5) {["id"] => string (1) "4" ["pid"] => string (1) "1" ["name"] => string (20) "TotalManagement" ["title"] => string (15) "Total management" ["submenu"] => array (3) {[0] => array (5) {["id"] => string (1) "5" ["name"] => string (12) "PC" ["menu_id"] => string (1) "4" ["title"] => string (17) "PC" ["access"] => int (1)} [1] => array (5) {["id"] => string (1) "6" ["name"] => string (13) "BJB" ["menu_id"] => string (1) "4" ["title"] => string (18) "BJB" ["access"] => int (1)} [2] => array (5) {["id"] => string (1) "7" ["name"] => string (16) "Select" ["menu_id"] => string (1) "4" ["title"] => string (15) "query" ["access"] => int (1 )}}}}} [2] => array (5) {["id"] => string (1) "2" ["pid"] => string (1) "0" ["name"] => string (14) "SystemSettings" ["title"] => string (12) "System Settings" ["submenu"] => array (1) {[0] => string (0) ""} [3] => array (5) {["id"] => string (1) "3" ["pid"] => string (1) "0" ["name"] => string (19) "Management" ["title"] => string (12) "background Management" ["submenu"] => array (1) {[0] => string (0) ""}}}