: This article mainly introduces how to use unset and array_filter to filter multi-dimensional arrays. if you are interested in the PHP Tutorial, refer to it.
Class A {/*** multi-dimensional array filtering sub-array containing the specified element * $ menu_list menu (A four-dimensional array) * $ mmenu receives the filtered menu * $ member_limits saved in the table's menu field */public function Multi_dimensional_array () {// $ menu_list = $ this-> _ getMemberMenuList (); $ mmenu = array (); $ member_limits = $ this-> member_limits (); // Use & write to the original data foreach ($ menu_list as & $ value) {foreach ($ value ['child '] as $ k => $ v) {if (! In_array ($ k, $ member_limits) {// clear the element unset ($ value ['child '] [$ k]); }}// array ($ this, "_ Filter") is equivalent to $ this-> _ Filter () $ mmenu = array_filter ($ menu_list, array ($ this, "_ Filter "));} /*** array_filter array callback function * filters out specified elements that are null */protected function _ Filter ($ value) {foreach ($ value ['child '] as $ k => $ v) {$ result = isset ($ value ['child']); if ($ result) {return $ result ;}}}}
The preceding section describes how to use unset and array_filter to filter multi-dimensional arrays, including related content. if you are interested in the PHP Tutorial, you can help.