Home > Backend Development > PHP Tutorial > 关于数组循环的一个有关问题

关于数组循环的一个有关问题

WBOY
Release: 2016-06-13 13:18:21
Original
867 people have browsed it

关于数组循环的一个问题
$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'], '<br>';
foreach($ar['sub'] as $v)
  echo "<a href="%24v%5Burl%5D">$v[caption]</a><br>";
<br><font color="#e78608">------解决方案--------------------</font><br>多少充都好。分析后,使用foreach就可以。
<br><font color="#e78608">------解决方案--------------------</font><br>顶帖收藏~~<br><br>
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

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'……
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template