开发者

How to make an array of menu items in PHP?

开发者 https://www.devze.com 2023-01-27 09:16 出处:网络
I have the following array in PHP for my menu ite开发者_高级运维ms: $items = array(\'Home\' => \'URL1\', \'Info\' => \'URL1\', \'Contact\' => \'URL3\');

I have the following array in PHP for my menu ite开发者_高级运维ms:

$items = array('Home' => 'URL1', 'Info' => 'URL1', 'Contact' => 'URL3');

Now I want to be able to add an extra value to one index at a time, indicating that it is a selected tab.

How would I do that in a fancy way?


you could use a multi dimensional array like so

$array['home']['url'] = 'url';
$array['home']['selected'] = true;

then if a particular url is selected you just set its selected value to true, you could also add other properties to the nav as well then for instance you could add a hidden value

$array['home']['hidden'] = true;

------- edit

apologies for the terrible formatting im doing this off my mobile phone


You could make an extra variable for it:

$items = array('Home' => 'URL1', 'Info' => 'URL1', 'Contact' => 'URL3');
$active_item='Info';
0

精彩评论

暂无评论...
验证码 换一张
取 消