关于数组循环的一个有关问题
程序员文章站
2024-01-23 10:10:22
...
关于数组循环的一个问题
$config['menu']['member']['coption'] = '搜索';
$config['menu']['member']['sub'][0]['caption']='百度';
$config['menu']['member']['sub'][0]['url']='http://www.baidu.com';
$config['menu']['member']['sub'][1]['caption']='谷歌';
$config['menu']['member']['sub'][1]['url']='http://www.google.com';
$config['menu']['member']['sub'][2]['caption']='SOSO';
$config['menu']['member']['sub'][2]['url']='http://www.soso.com';
让它循环成这样
搜索(主菜单)
百度(子菜单)
------解决方案--------------------
Array
(
[menu] => Array
(
[member] => Array
(
[coption] => 搜索
[sub] => Array
(
[0] => Array
(
[caption] => 百度
[url] => http://www.baidu.com
)
[1] => Array
(
[caption] => 谷歌
[url] => http://www.google.com
)
[2] => Array
(
[caption] => SOSO
[url] => http://www.soso.com
)
)
)
)
)这样看不就清楚了吗
smarty
(主菜单)
(子菜单)
------解决方案--------------------
$config['menu']['member']['coption'] = '搜索';
$config['menu']['member']['sub'][0]['caption']='百度';
$config['menu']['member']['sub'][0]['url']='http://www.baidu.com';
$config['menu']['member']['sub'][1]['caption']='谷歌';
$config['menu']['member']['sub'][1]['url']='http://www.google.com';
$config['menu']['member']['sub'][2]['caption']='SOSO';
$config['menu']['member']['sub'][2]['url']='http://www.soso.com';
让它循环成这样
搜索(主菜单)
百度(子菜单)
------解决方案--------------------
Array
(
[menu] => Array
(
[member] => Array
(
[coption] => 搜索
[sub] => Array
(
[0] => Array
(
[caption] => 百度
[url] => http://www.baidu.com
)
[1] => Array
(
[caption] => 谷歌
[url] => http://www.google.com
)
[2] => Array
(
[caption] => SOSO
[url] => http://www.soso.com
)
)
)
)
)这样看不就清楚了吗
smarty
(主菜单)
(子菜单)
------解决方案--------------------
- PHP code
$config['menu']['member']['coption'] = '搜索';$config['menu']['member']['sub'][0]['caption']='百度';$config['menu']['member']['sub'][0]['url']='http://www.baidu.com';$config['menu']['member']['sub'][1]['caption']='谷歌';$config['menu']['member']['sub'][1]['url']='http://www.google.com';$config['menu']['member']['sub'][2]['caption']='SOSO';$config['menu']['member']['sub'][2]['url']='http://www.soso.com';$ar = $config['menu']['member'];echo $ar['coption'], '
';foreach($ar['sub'] as $v) echo "$v[caption]
";
------解决方案--------------------
多少充都好。分析后,使用foreach就可以。
------解决方案--------------------
顶帖收藏~~
------解决方案--------------------
相关文章
相关视频
上一篇: php上传图片类及用法示例,_PHP教程