标签:
现有树形结构如下 若给出cat_id 9 如何查处 9 的所有上级 和 所有下级
<?php array ( 1 =>array ( ‘cat_id‘ => ‘1‘, ‘cat_name‘ => ‘手机类型‘, ‘parent_id‘ => ‘0‘, ‘child‘ =>array ( 2 => array ( ‘cat_id‘ => ‘2‘, ‘cat_name‘ => ‘CDMA手机‘, ‘parent_id‘ => ‘1‘, ), 3 => array ( ‘cat_id‘ => ‘3‘, ‘cat_name‘ => ‘GSM手机‘, ‘parent_id‘ => ‘1‘, ), 4 => array ( ‘cat_id‘ => ‘4‘, ‘cat_name‘ => ‘3G手机‘, ‘parent_id‘ => ‘1‘, ), 5 => array ( ‘cat_id‘ => ‘5‘, ‘cat_name‘ => ‘双模手机‘, ‘parent_id‘ => ‘1‘, ), ), ), 6 => array ( ‘cat_id‘ => ‘6‘, ‘cat_name‘ => ‘手机配件‘, ‘parent_id‘ => ‘0‘, ‘child‘ => array ( 7 => array ( ‘cat_id‘ => ‘7‘, ‘cat_name‘ => ‘充电器‘, ‘parent_id‘ => ‘6‘, ), 8 => array ( ‘cat_id‘ => ‘8‘, ‘cat_name‘ => ‘耳机‘, ‘parent_id‘ => ‘6‘, ), 9 => array ( ‘cat_id‘ => ‘9‘, ‘cat_name‘ => ‘电池‘, ‘parent_id‘ => ‘6‘, ‘child‘ => array( 101=>array ( ‘cat_id‘ => ‘101‘, ‘cat_name‘ => ‘充电器101‘, ‘parent_id‘ => ‘9‘, ), 102=>array ( ‘cat_id‘ => ‘102‘, ‘cat_name‘ => ‘充电器102‘, ‘parent_id‘ => ‘9‘, ), 103=>array ( ‘cat_id‘ => ‘103‘, ‘cat_name‘ => ‘充电器103‘, ‘parent_id‘ => ‘9‘, ), ), ), 11 => array ( ‘cat_id‘ => ‘11‘, ‘cat_name‘ => ‘读卡器和内存卡‘, ‘parent_id‘ => ‘6‘, ), ), ), 12 => array ( ‘cat_id‘ => ‘12‘, ‘cat_name‘ => ‘充值卡‘, ‘parent_id‘ => ‘0‘, ‘child‘ => array ( 13 => array ( ‘cat_id‘ => ‘13‘, ‘cat_name‘ => ‘小灵通/固话充值卡‘, ‘parent_id‘ => ‘12‘, ), 14 => array ( ‘cat_id‘ => ‘14‘, ‘cat_name‘ => ‘移动手机充值卡‘, ‘parent_id‘ => ‘12‘, ), 15 => array ( ‘cat_id‘ => ‘15‘, ‘cat_name‘ => ‘联通手机充值卡‘, ‘parent_id‘ => ‘12‘, ), ), ), );
标签:
原文地址:http://my.oschina.net/cgjcgs/blog/493609