I have a function checkLevel($upper,$lower)
. Suppose I pass checkLevel(2,4)
. Now 2 is the parent of 3 and 3 is the parent of 4. The gap between them is of 2. Similarly, if I enter checkLevel(1,4)
, the result should be 3 because 1 is the parent of 2, 2 is the parent of 3 and 3 is the parent of 4. The number of levels are 3. Please see the image below. Can any one help me out?
如何确定上下级别之间的级别数?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongxu8533486 2015-11-02 12:20关注
It should work.
$level = 0; function checkLevel($start,$end) { global $level; $level++; $array = array(0=>array('id'=>1,'parent_id'=>'0','test'=>'a'),1=>array('id'=>2,'parent_id'=>'1','test'=>'b'),2=>array('id'=>3,'parent_id'=>'2','test'=>'c'),3=>array('id'=>4,'parent_id'=>'3','test'=>'d')); $key = array_search($end,array_column($array, 'id')); if($key == $start) return; else checkLevel($start,$key); //echo $key;exit; } checkLevel(2,4); echo $level;
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度