如何删除多维数组 里面的一个值 求大神解答

想删除 subCats 里面的 [Did] 要如何做 在网上找了好多资料 但是不会用 求大神解答下

 $cats  var_export如下
array (
  0 => 
  array (
    'id' => '907362758',
    'name' => '新品专区',
    'subCats' => 
    array (
    ),
  ),
  1 => 
  array (
    'id' => '907362759',
    'name' => '保暖上装',
    'subCats' => 
    array (
      0 => 
      array (
        'id' => '907362760',
        'Did' => '907362759',
        'name' => '假两件(衬衫领)',
      ),
      1 => 
      array (
        'id' => '907362761',
        'Did' => '907362759',
        'name' => 'V领上装',
      ),
      2 => 
      array (
        'id' => '907362762',
        'Did' => '907362759',
        'name' => '商务休闲',
      ),
      3 => 
      array (
        'id' => '907362763',
        'Did' => '907362759',
        'name' => '时尚居家',
      ),
    ),
  ),
  2 => 
  array (
    'id' => '907362764',
    'name' => '保暖套装',
    'subCats' => 
    array (
      0 => 
      array (
        'id' => '907362765',
        'Did' => '907362764',
        'name' => '男士套装',
      ),
      1 => 
      array (
        'id' => '907362766',
        'Did' => '907362764',
        'name' => '女士套装',
      ),
      2 => 
      array (
        'id' => '907362767',
        'Did' => '907362764',
        'name' => '基础打底内衣',
      ),
      3 => 
      array (
        'id' => '907362768',
        'Did' => '907362764',
        'name' => '加绒加厚',
      ),
      4 => 
      array (
        'id' => '907362769',
        'Did' => '907362764',
        'name' => '全棉内衣',
      ),
      5 => 
      array (
        'id' => '907362770',
        'Did' => '907362764',
        'name' => '羊毛内衣',
      ),
      6 => 
      array (
        'id' => '907362771',
        'Did' => '907362764',
        'name' => '驼绒内衣',
      ),
      7 => 
      array (
        'id' => '907362772',
        'Did' => '907362764',
        'name' => '莱卡内衣',
      ),
      8 => 
      array (
        'id' => '907419493',
        'Did' => '907362764',
        'name' => '本命年',
      ),
    ),
  ),
  3 => 
  array (
    'id' => '907362775',
    'name' => '保暖裤',
    'subCats' => 
    array (
      0 => 
      array (
        'id' => '907362776',
        'Did' => '907362775',
        'name' => '薄款打底裤',
      ),
      1 => 
      array (
        'id' => '907362778',
        'Did' => '907362775',
        'name' => '加绒加厚',
      ),
    ),
  ),
  4 => 
  array (
    'id' => '907362795',
    'name' => '内裤系列',
    'subCats' => 
    array (
      0 => 
      array (
        'id' => '907362796',
        'Did' => '907362795',
        'name' => '男士内裤',
      ),
      1 => 
      array (
        'id' => '907362797',
        'Did' => '907362795',
        'name' => '女士内裤',
      ),
      2 => 
      array (
        'id' => '907362799',
        'Did' => '907362795',
        'name' => '平角裤',
      ),
      3 => 
      array (
        'id' => '907363601',
        'Did' => '907362795',
        'name' => '植物纤维',
      ),
      4 => 
      array (
        'id' => '907363603',
        'Did' => '907362795',
        'name' => '星期裤',
      ),
      5 => 
      array (
        'id' => '907363604',
        'Did' => '907362795',
        'name' => '礼盒装',
      ),
    ),
  ),
  5 => 
  array (
    'id' => '907362787',
    'name' => '袜类专区',
    'subCats' => 
    array (
      0 => 
      array (
        'id' => '907362788',
        'Did' => '907362787',
        'name' => '棉袜',
      ),
      1 => 
      array (
        'id' => '907362789',
        'Did' => '907362787',
        'name' => '丝袜',
      ),
      2 => 
      array (
        'id' => '907362790',
        'Did' => '907362787',
        'name' => '全棉袜',
      ),
      3 => 
      array (
        'id' => '907362791',
        'Did' => '907362787',
        'name' => '精梳棉袜',
      ),
      4 => 
      array (
        'id' => '907362792',
        'Did' => '907362787',
        'name' => '春秋棉袜',
      ),
      5 => 
      array (
        'id' => '907362793',
        'Did' => '907362787',
        'name' => '夏季透气',
      ),
      6 => 
      array (
        'id' => '907362794',
        'Did' => '907362787',
        'name' => '冬季加厚',
      ),
    ),
  ),
  6 => 
  array (
    'id' => '907362784',
    'name' => '背心-T恤',
    'subCats' => 
    array (
      0 => 
      array (
        'id' => '907362785',
        'Did' => '907362784',
        'name' => '男士背心-T恤',
      ),
    ),
  ),
  7 => 
  array (
    'id' => '907363605',
    'name' => '运动文胸',
    'subCats' => 
    array (
    ),
  ),
  8 => 
  array (
    'id' => '907363606',
    'name' => '清仓专区',
    'subCats' => 
    array (
    ),
  ),
  9 => 
  array (
    'id' => '907363607',
    'name' => '男士专区',
    'subCats' => 
    array (
    ),
  ),
  10 => 
  array (
    'id' => '907363608',
    'name' => '女士专区',
    'subCats' => 
    array (
    ),
  ),
  11 => 
  array (
    'id' => '907363609',
    'name' => '送礼专区',
    'subCats' => 
    array (
    ),
  ),
  12 => 
  array (
    'id' => '100563948',
    'name' => '推荐分类',
    'subCats' => 
    array (
      0 => 
      array (
        'id' => '100563948',
        'Did' => '100563948',
        'name' => '热卖推荐',
      ),
      1 => 
      array (
        'id' => '100563948',
        'Did' => '100563948',
        'name' => '套装推荐',
      ),
      2 => 
      array (
        'id' => '100563948',
        'Did' => '100563948',
        'name' => '衬衫领推荐',
      ),
      3 => 
      array (
        'id' => '100563948',
        'Did' => '100563948',
        'name' => '内裤',
      ),
    ),
  ),
)

1个回答

foreach($cats AS $key=>$value){
if($value['subCats']){
foreach($value['subCats'] AS $k=>$v){
unset($cats[$key]['subCats'][$k]['Did']);
}
}
}

qq_22916833
qq_22916833 谢大神
接近 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐