閫掑綊鍒犻櫎

鏈嬪弸缁欐垜鍑虹殑涓閬撻锛屽垹闄ら噷闈㈠惈鏈塱s_deleted鐨勯敭鍊煎

{
    "name": "骞夸笢姹曞ご鍗庝鲸涓",
    "is_deleted": 0,
    "children": [
        {
            "name": "瀹為獙妤",
            "is_deleted": 0,
            "children": [
                {
                    "name": "瀹為獙妤1",
                    "is_deleted": 1,
                    "children": []
                },
                {
                    "name": "榛勯工妤",
                    "is_deleted": 0,
                    "children": [
                        {
                            "name": "瀹為獙妤1",
                            "is_deleted": 0,
                            "children": [
                                {
                                    "name": "瀹為獙妤11",
                                    "is_deleted": 0,
                                    "children": []
                                },
                                {
                                    "name": "瀹為獙妤22",
                                    "is_deleted": 1,
                                    "children": []
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

鏈潵浠ヤ负鏄竴涓尯瀹规槗鐨勯鐩紝鍐欒捣鏉ヨ繕鏄病閭d箞绠鍗曪紝浣嗘槸涔熸尯鏈夋敹鑾蜂簡銆

<?php
$map = ' {
    "name": "骞夸笢姹曞ご鍗庝鲸涓",
    "is_deleted": 0,
    "children": [
        {
            "name": "瀹為獙妤",
            "is_deleted": 0,
            "children": [
                {
                    "name": "瀹為獙妤1",
                    "is_deleted": 1,
                    "children": []
                },
                {
                    "name": "榛勯工妤",
                    "is_deleted": 0,
                    "children": [
                        {
                            "name": "瀹為獙妤1",
                            "is_deleted": 0,
                            "children": [
                                {
                                    "name": "瀹為獙妤11",
                                    "is_deleted": 0,
                                    "children": []
                                },
                                {
                                    "name": "瀹為獙妤22",
                                    "is_deleted": 1,
                                    "children": []
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

    ';
    $map = json_decode($map, true);
    if($map['is_deleted'] == 1){
        $map = [];
    }
    if(!empty($map["children"])){
        $map["children"] = del_deleted_arr($map["children"]);
    }
    echo json_encode($map);exit;


    function del_deleted_arr($arr){
        // echo json_encode($arr);exit;
        if($arr){
            for($key=0; $key<count($arr);$key++){
            //foreach ($arr as $key => $value) {
                if($arr[$key]['is_deleted'] == 1){
                     array_splice($arr, $key, 1);
                     $key = $key -1;
                } 
                $arr[$key]['children'] = del_deleted_arr($arr[$key]['children']);
            }
            //$arr = array_values($arr);
            return  $arr;
        }else{
            return [];
        }
    }

All posts

Other pages


Deprecated: 鏂囦欢 娌℃湁 comments.php 鐨勪富棰 鑷増鏈 3.0.0 璧峰凡寮冪敤锛屼笖娌℃湁鍙敤鐨勬浛浠c 璇峰湪鎮ㄧ殑涓婚涓寘鍚竴涓 comments.php 妯℃澘銆 in /www/wwwroot/liguoqi.site/wp-includes/functions.php on line 6078

鍙戣〃鍥炲

鎮ㄧ殑鐢靛瓙閭鍦板潃涓嶄細琚叕寮銆 蹇呭~椤瑰凡鐢 * 鏍囨敞