Filter function function my_filter($arr){$filterDatum = 'what you set';foreach($arr as $k => &$item){if(is_array($item){my_filter($item);}else{ // item is an elementif"/> Filter function function my_filter($arr){$filterDatum = 'what you set';foreach($arr as $k => &$item){if(is_array($item){my_filter($item);}else{ // item is an elementif">

Home >Backend Development >PHP Tutorial >Summary | PHP multidimensional array filtering method c# multidimensional array matlab multidimensional array multidimensional array pointer

Summary | PHP multidimensional array filtering method c# multidimensional array matlab multidimensional array multidimensional array pointer

WBOY
WBOYOriginal
2016-07-29 08:50:501308browse

data-id="1190000005075514" data-license="nd">

Filter function

<code>function my_filter($arr){
    $filterDatum = 'what you set';
    
    foreach($arr as $k => &$item){
        if(is_array($item){
            my_filter($item);
        }else{ // item is an element
            if($item == $filterDatum){
                unset($arr[$k]);
            }
        }
    }
    
    return $arr;
}
</code>

Filter implementation statement

<code>$arr = [
    // who know what the array looks like.
];

$arr = array_filter($arr, 'my_filter');
</code>

BINGO

Reference

  1. Q&A on this site

The above has introduced the summary | PHP multi-dimensional array filtering method, including the content of PHP multi-dimensional arrays. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn