php导航分类 求大神
array(10) {
[0] => array(5) {
["id"] => string(1) "1"
["pid"] => string(1) "0"
["title"] => string(6) "讨论"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[1] => array(5) {
["id"] => string(1) "2"
["pid"] => string(1) "0"
["title"] => string(6) "下载"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[2] => array(5) {
["id"] => string(1) "3"
["pid"] => string(1) "0"
["title"] => string(9) "官方区"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[3] => array(5) {
["id"] => string(1) "4"
["pid"] => string(1) "1"
["title"] => string(12) "求助交流"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[4] => array(5) {
["id"] => string(1) "5"
["pid"] => string(1) "1"
["title"] => string(12) "技术分享"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[5] => array(5) {
["id"] => string(1) "6"
["pid"] => string(1) "2"
["title"] => string(9) "电子书"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[6] => array(5) {
["id"] => string(1) "7"
["pid"] => string(1) "2"
["title"] => string(6) "软件"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[7] => array(5) {
["id"] => string(1) "8"
["pid"] => string(1) "3"
["title"] => string(6) "反馈"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[8] => array(5) {
["id"] => string(1) "9"
["pid"] => string(1) "1"
["title"] => string(12) "综合讨论"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[9] => array(5) {
["id"] => string(2) "10"
["pid"] => string(1) "3"
["title"] => string(12) "程序发布"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
}
pid为0的是*导航 有3个 id为0,1,2
也就是讨论 下载 官方区
pid不为0的是子导航 有7个 id为3,4,5,6,7,8,9
也就是求助交流 技术分享 电子书 软件 反馈 综合讨论 程序发布
子导航的pid就是*导航的id 也就是讨论
下面是求助交流 技术分享 综合讨论
现在需要写一个函数 参数就是那十堆数组 要求返回一个数组$return
$return['top']就是那些*导航数组 3组数组
array(3){..*导航`讨论 下载 官方区数组..}
$return['child']就是那些子导航数组 注意的是也是3组数组 也就是和*数组对应
array(3){
[0] => array(3){..求助交流 技术分享 综合讨论数组.}
[1] => array(2){..电子书 软件数组..}
[2] => array(2){..反馈 程序发布数组..}
}
数组1属于讨论数组的子导航数组
数组2是下载数组的子导航数组
数组3就是官方区数组的子导航数组
回复内容:
下面是10个数组
array(10) {
[0] => array(5) {
["id"] => string(1) "1"
["pid"] => string(1) "0"
["title"] => string(6) "讨论"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[1] => array(5) {
["id"] => string(1) "2"
["pid"] => string(1) "0"
["title"] => string(6) "下载"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[2] => array(5) {
["id"] => string(1) "3"
["pid"] => string(1) "0"
["title"] => string(9) "官方区"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[3] => array(5) {
["id"] => string(1) "4"
["pid"] => string(1) "1"
["title"] => string(12) "求助交流"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[4] => array(5) {
["id"] => string(1) "5"
["pid"] => string(1) "1"
["title"] => string(12) "技术分享"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[5] => array(5) {
["id"] => string(1) "6"
["pid"] => string(1) "2"
["title"] => string(9) "电子书"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[6] => array(5) {
["id"] => string(1) "7"
["pid"] => string(1) "2"
["title"] => string(6) "软件"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[7] => array(5) {
["id"] => string(1) "8"
["pid"] => string(1) "3"
["title"] => string(6) "反馈"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[8] => array(5) {
["id"] => string(1) "9"
["pid"] => string(1) "1"
["title"] => string(12) "综合讨论"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
[9] => array(5) {
["id"] => string(2) "10"
["pid"] => string(1) "3"
["title"] => string(12) "程序发布"
["sort"] => string(1) "0"
["siatus"] => string(1) "0"
}
}
pid为0的是*导航 有3个 id为0,1,2
也就是讨论 下载 官方区
pid不为0的是子导航 有7个 id为3,4,5,6,7,8,9
也就是求助交流 技术分享 电子书 软件 反馈 综合讨论 程序发布
子导航的pid就是*导航的id 也就是讨论
下面是求助交流 技术分享 综合讨论
现在需要写一个函数 参数就是那十堆数组 要求返回一个数组$return
$return['top']就是那些*导航数组 3组数组
array(3){..*导航`讨论 下载 官方区数组..}
$return['child']就是那些子导航数组 注意的是也是3组数组 也就是和*数组对应
array(3){
[0] => array(3){..求助交流 技术分享 综合讨论数组.}
[1] => array(2){..电子书 软件数组..}
[2] => array(2){..反馈 程序发布数组..}
}
数组1属于讨论数组的子导航数组
数组2是下载数组的子导航数组
数组3就是官方区数组的子导航数组
function getFormate($arr){
$top = $child = array();
foreach($arr as $val){
if($val['pid'] == 0){
$top[] = $val;
}else{
$child[ $val['pid'] ][] = $val;
}
}
return array('top' => $top, 'child' => array_values($child) );
}
这应该是你需要的
推荐阅读
-
php导航分类 求大神
-
用mac实现php开发socket,但是直接在socket——blind直接丢失,求大神解答
-
apache配置PHP5.5后启动服务报错 求大神帮忙
-
php-求大神解答 关于PHP项目提升性能的方法
-
求大神来解决codeigniter框架里面ajax调用php不允许访问的问题
-
使用php时出现了no database selected的问题 求大神帮助
-
html网页中插入script脚本,src指向php文件,怎么在html中显示php返回的数据?求大神赐教。
-
跳转-PHP后台注销登录以后点击”后退“按钮仍然能回去,求大神指导~~~感激不尽
-
php加密-PHP解密问题,求大神给看看
-
php表单插入数据库,求大神帮忙