按属性筛选数组


Filter Array by property

如何在PHP中过滤这个数组,使其仅包含[is_published] = 1的条目?

我整个下午都在看堆栈溢出,并尝试了filter_array和其他方法,但我就是做不好......

FB_manager_array2: Array
(
    [0] => Array
        (
            [data] => Array
                (
                    [0] => Array
                        (
                            [id] => 244987165675334
                            [is_published] => 1
                            [name] => Zitecraft.com
                        )
                    [1] => Array
                        (
                            [id] => 437060646380356
                            [is_published] => 1
                            [name] => Beauty & care Alexandra
                        )
                    [2] => Array
                        (
                            [id] => 663302210366640
                            [is_published] => 1
                            [name] => Tiramisu Gelato ijssalon
                        )
                    [3] => Array
                        (
                            [id] => 295426223953905
                            [is_published] => 1
                            [name] => Ck's Hairstyling
                        )
                    [4] => Array
                        (
                            [id] => 213820525062
                            [is_published] => 1
                            [name] => Citynumbers.com - Feel like going out tonight?
                        )
                    [5] => Array
                        (
                            [id] => 114373308748798
                            [is_published] => 1
                            [name] => YOLO: You Only Live Once
                        )
                    [6] => Array
                        (
                            [id] => 200408800066160
                            [is_published] => 
                            [name] => Citynumbers Social Widget
                        )
                )
            [paging] => Array
                (
                    [cursors] => Array
                        (
                            [before] => MjQ0OTg3MTY1Njc1MzM0
                            [after] => MjAwNDA4ODAwMDY2MTYw
                        )
                )
        )
)

带有array_filter:

$FB_manager_array2[0]['data'] = array_filter($FB_manager_array2[0]['data'], function($v) {
    return $v['is_published'] == '1';
});