doulun1915 2014-06-11 11:05
浏览 23

如果[conditions] index没有null,则删除数组中的数组

Here is array output

Array
(
    [conditions] => Array
        (
            [Service.organization_size_id] => Array
                (
                    [0] => 1
                )

        )

    [limit] => 10
    [joins] => Array
        (
            [0] => Array
                (
                    [type] => inner
                    [conditions] => Array
                        (
                            [ServicesToOrganizationTypes.organization_type_id] => Array
                                (
                                    [1] => 1
                                )

                            [0] => ServicesToOrganizationTypes.service_id = Service.id
                        )

                )

            [1] => Array
                (
                    [type] => LEFT
                    [conditions] => Array
                        (
                            [ServicesToLifeCycles.life_cycle_id] => Array
                                (
                                    [1] => 1
                                )

                            [0] => ServicesToLifeCycles.service_id = Service.id
                        )

                )

            [3] => Array
                (
                    [type] => inner
                    [conditions] => Array
                        (
                            [servicestoindustries.industry_id] => 
                            [0] => servicestoindustries.service_id = Service.id
                        )

                )
        )

    [group] => Service.id
)

I want to remove a array part if [conditions] has no value for exmple below

[3] => Array
                   (
                       [type] => inner
                       [conditions] => Array
                           (
                               [servicestoindustries.industry_id] => // here has no value 
                               [0] => servicestoindustries.service_id = Service.id
                           )

                   )

So i want to remove it from array

[3] => Array
                   (
                       [type] => inner
                       [conditions] => Array
                           (
                               [servicestoindustries.industry_id] =>                      // here has no value 
                               [0] => servicestoindustries.service_id = Service.id
                           )

                   )
  • 写回答

1条回答 默认 最新

  • dsnnvpobaljihv3490 2014-06-11 11:38
    关注

    You can try this one (untested)

    <?php
    /**
     * A redundant function to clean array
     */
    function clean_array(&$array) {
        foreach($array as $key => $value) {
            if(is_array($value)) {
                clean_array($value); // If array, call the function itself
            } else if(empty($value)) {
                // Two choices
                unset($array[$key]); // Delete the array part
                unset($array) // Delete the whole array
            }
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度