Filter multidimensional arrays

后端 未结 1 1310
闹比i
闹比i 2020-12-20 02:57
Array
(
    [user_mob_1] => Array
        (
            [mob_code] => 06
            [mob] => 069633345
            [type] => 1
            [phone_id] =&         


        
相关标签:
1条回答
  • 2020-12-20 03:23

    Your idea of using a built-in function like array_filter is a very good one; PHP has lots of these that can make your life easier.

    Specifically, array_filter accepts a callback that you can use to customize the filtering logic. This would work:

    $filtered = array_filter($array, function($el) { return !empty($el['mob']); });
    

    Here the callback is supplied as an anonymous function.

    0 讨论(0)
提交回复
热议问题