看不懂啊请给小弟我详细解释下 - PHP 首页- Web开发
- Android
- J2EE
- PHP
- Linux/Unix
- MySql
- C#
- 更多...
当前位置: 代码迷 » PHP » 看不懂啊请给小弟我详细解释下
看不懂啊请给小弟我详细解释下
www.MyException.Cn,网友分享于:2014-06-30 浏览:3次 看不懂啊,请给我详细解释下.
foreach ($categories as $key => $value) {
$upid = $value['upid'];
$categories[$key]['level'] = 0;
if ($upid && isset($categories[$upid])) {
$categories[$upid]['children'][] = $key; // 这个三维数组是什么意思? 这个$key值是怎么赋予这个三维数组的/
while ($upid && isset($categories[$upid])) {
$categories[$upid]['allnodes'][] = $key;
$categories[$upid]['count'] += $categories[$key]['count']; //这个又是怎计算的, ??
$categories[$key]['level'] += 1;
$categories[$key]['parent'][$upid] = $categories[$upid]['catname']; //这个,这个也不懂
$upid = $categories[$upid]['upid']; //这个也不懂.
}
$categories[$key]['parent'] = array_reverse($categories[$key]['parent'], true);
}
if ($categories[$key]['level'] == 0) {
$rootcategories[] = $key;
}
}
------解决思路----------------------$categories[$upid]['children'][] = $key;
例如 $upid=1, $key=2;
$categories[$upid]['children'][] = $key;
等于
$categories[1]['children'] 是一个数组,然后$key作为插入到数组最后。
执行完后
$categories = array(
1 => array(
'children' => array(2)
)
);
categories[$upid]['count'] += $categories[$key]['count'];
等于
categories[$upid]['count'] = categories[$upid]['count'] + $categories[$key]['count'];
$categories[$key]['parent'][$upid] = $categories[$upid]['catname'];
$upid = $categories[$upid]['upid'];
这两句都是直接赋值。
------解决思路----------------------$categories[$upid]['children'][] = xxx 表示在$categories[$upid]['children'] 数组插入一个新元素。
例如
$arr = array('key'=>array());
$arr['key'][] = 1;
$arr['key'][] = 2;
$arr['key'][] = 3;
执行后.
$arr = array(
'key' => array(1,2,3)
);
$categories[$upid]['count'] = $categories[$upid]['count'] + $categories[$key]['count'];
categories[$upid]['count'] 與 $categories[$key]['count'] 是應該是兩個數值,所以可以相加。
你可以print_r($categories); 看看$categories裡面是什麼。
$categories[$key]['parent'][$upid] = $categories[$upid]['catname'];
這個可以簡單點
$key = 'a';
$upid = 'b';
$categories[$key]['parent'][$upid] = 1;
$categories[$upid]['catname'] = 2;
相當於
$categories['a']['parent']['b'] = 1;
$categories['b']['catname'] = 2;
執行
$categories[$key]['parent'][$upid] = $categories[$upid]['catname'];
相當於
$categories['a']['parent']['b'] = $categories['b']['catname'];
所以
$categories[$key]['parent'][$upid] = 2;
------解决思路----------------------学编程,就不能怕动手
在这段代码的前后分别 print_r($categories);
一切净收眼底
------解决思路----------------------错别字哇。。。应该是尽收眼底