Use unset and array_filter to filter multi-dimensional arrays

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.