PHP array
2 hours ago, Joveice said:So I'm trying to do this array but I have no clue on how it's done since I dident understand the documentation at all.
What I want to do is have an array with 4 values, the last value is going to be another array. like this Name > A name, Link > A link, Icon > Icon-name, Trigger > (1,2,3,4)
And I want to be able to store more of them in there. so I can do a foreach to get all the values out of it and make a row with it (gonna use this for a navigation bar).
$menu = array( array('name' => 'Home', 'link' => '/', 'icon' => 'fa fa-home', 'trigger' => array('Home')), array('name' => 'Shop', 'link' => '/shop', 'icon' => 'fa fa-shopping-cart', 'trigger' => array('Shop','Shop - Products')) );This is what I tryed, but I don't think it worked (or I'm doing it wrong)
2 hours ago, Joveice said:That doesent work, tho I figured it out now, just how to do the foreach I have no clue of now. $menu[0]['name'] returns Home, tho how I can get the [0]value in foreach I have no idea
Hope this will be helpfull:
<?php $menu = array( array('name' => 'Home', 'link' => '/', 'icon' => 'fa fa-home', 'trigger' => array('Home')), //$menuitem array('name' => 'Shop', 'link' => '/shop', 'icon' => 'fa fa-shopping-cart', 'trigger' => array('Shop','Shop - Products')) //$menuitem ); foreach ($menu as $menuitem) { //First iteration //$menuitem['name'] = 'Home' //$menuitem['link'] = '/' //$menuitem['trigger'][0] = 'Home' //etc. //Second iteration //$menuitem['name'] = 'Shop' //$menuitem['link'] = '/shop' //$menuitem['trigger'][0] = 'Shop' //$menuitem['trigger'][1] = 'Shop - Products' //etc. //or loop trough $menuitem['trigger'] foreach ($menuitem['trigger'] as $k => $value) { //$k is the array index (0,1,2,etc) //$value wil hold Home, Shop or Shop - Products } } ?>
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now