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

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

Jun 13, 2016 pm 01:18 PM
config menu sub

关于数组循环的一个问题
$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'……
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to fix error 0xC00CE556 returned by the .NET parser How to fix error 0xC00CE556 returned by the .NET parser Apr 25, 2023 am 08:34 AM

While installing a new version of an application, Windows may display this error message "An error occurred while parsing C:\\Windows\Microsoft.Net\Framework\v2.0.50727\Config\machine.configParser returned error 0xC00CE556". This problem also occurs when your system boots. No matter what situation you encounter this problem, .NETFramework is the real culprit behind the scenes. There are some very simple fixes you can use to stop this error code from appearing again. Fix 1 – Replace corrupted files You can easily replace corrupted ma from the original directory

How to use ThinkPHP\Config for configuration management in php? How to use ThinkPHP\Config for configuration management in php? May 31, 2023 pm 02:31 PM

With the continuous development of the PHP language, ThinkPHP, which is widely used in the PHP back-end framework, is also constantly improving. As business scenarios become increasingly complex, the demand for configuration management in ThinkPHP is also increasing. In this context, ThinkPHP provides rich configuration management functions. Today we will introduce how to implement configuration management through ThinkPHPConfig. 1. Introduction to ThinkPHPConfig ThinkPHPConfig is Thin

How does php use CodeIgniter\Config for configuration management? How does php use CodeIgniter\Config for configuration management? Jun 02, 2023 pm 06:01 PM

1. Introduction to CodeIgniter CodeIgniter is a lightweight and comprehensive PHP development framework designed to provide web developers with fast and powerful tools to build web applications. It is an open source framework that uses the MVC architecture pattern to achieve rapid development and basic functions, while supporting a variety of databases. 2. Introduction to the Config library The Config library is a component in the CodeIgniter framework and is used to configure and manage code. The Config library contains many

Free open source tool: Shorten the macOS menu bar and hide less commonly used content Free open source tool: Shorten the macOS menu bar and hide less commonly used content Dec 01, 2023 pm 02:38 PM

For macOS users, some commonly used software may be directly accessible through the Menubar in the upper right corner. However, as time goes by, you will find that there are more and more icons and your Menubar will gradually become longer and longer. If you use a MacBook, it is more likely to go beyond the middle position of the "bangs". This time I recommend a set of free and open source macOS tools called HiddenBar. Its biggest function is to allow you to shorten the Menubar and hide things that are not commonly used. Separated display area After installing this app, a separated area map will appear. Things on the left side of this mark will be hidden, and only things on the right side will be visible. Usage method 1: Set the partition first, and then move the less frequently used apps to the left of the partition. 2

Laravel development: How to configure an application using Laravel Config? Laravel development: How to configure an application using Laravel Config? Jun 13, 2023 pm 02:55 PM

Laravel is a popular PHP framework that provides many convenient features to developers. One of the most useful features are configuration files, which can be used to store settings and options within an application. In this article, we will explain how to configure an application using LaravelConfig. What is a configuration file? Within the application, there are many settings to set up and manage. These settings include database information, third-party API keys, and application behavior. In some cases, these settings may need to be

FCC filing for Sonos Sub Mini confirms cylindrical design, could launch in summer FCC filing for Sonos Sub Mini confirms cylindrical design, could launch in summer Apr 18, 2023 pm 10:07 PM

Sonos just launched its most affordable soundbar yet, the Ray. The product launched as the company's next product will be a good companion to the compact Ray and Beam soundbars. Last month, we got a detailed look at the Sonos SubMini thanks to renders created by TheVerge after seeing leaked images of the product. Now, Sonos FCC documents (via The Verge) reveal the underside of the Sonos Sub Mini and confirm that the expected design is accurate. The FCC image also points to a black and white variant, which is intended to match the options on the Ray and Beam soundbars (as well as other Sonos products)

How to use Phalcon\Config for configuration management in PHP? How to use Phalcon\Config for configuration management in PHP? May 31, 2023 pm 08:40 PM

Phalcon is a PHP framework that provides powerful and efficient tools to build web applications, one of which is PhalconConfig. PhalconConfig provides a flexible way to manage configuration information in applications. In this article, we will introduce the basic concepts of PhalconConfig and how to use it for configuration management in PHP applications. 1. What is PhalconConfig? PhalconConfig is a

What should I do if the vue menu does not refresh? What should I do if the vue menu does not refresh? Dec 26, 2022 pm 04:36 PM

Solution to vue menu not refreshing: 1. Write "<router-view v-if="!$route.meta.keepAlive"></router-view>" on the index page; 2. Set the cache name to "test -keep-alive"; 3. Configure "{path: '/Material',name: 'Material'...}" in the router file.

See all articles