Jump to content

PHP array iteration


Guest a1132732
 Share

Recommended Posts

Guest a1132732

Howdy im new to php and i have created a multidimensional array okayhowever i need to create a while statement that will iterate through the array and put the values which are days into radio buttons. Ill show you my code so far<?php$monday=array(1=>'honey pepper chicken','smoked chicken with spinach','pork spare ribs','lamb with peri peri chips','foccacia', 'Avocado Baguette');$tuesday=array(1=>'toast','smoked salmon','caesar salad','chips','chicken parmigaina','fried rice');$wednesday=array(1=>'pork spare ribs','lamb with peri peri chips','foccacia', 'Avocado Baguette');$thursday=array(1=>'chicken parmigaina','fried rice','gourmet italian pizza','honey pepper chicken');$friday=array(1=>'fried rice','gourmet italian pizza','honey pepper chicken','smoked chicken with spinach','pork spare ribs');$days=array('Monday:'=>$monday,'Tuesday:'=>$tuesday,'Wednesday:'=>$wednesday,'Thursday:'=>$thursday,'Friday:'=>$friday);?>i need the days to be put into radio buttons can i do this by iterating throuhg the array im having trouble working it out.

Link to comment
Share on other sites

Research the foreach() function as you are dealing with arrays. it makes life a whole lot easier, and php code soo much cleaner :)

<?php$monday=array('honey pepper chicken','smoked chicken with spinach','pork spare ribs','lamb with peri peri chips','foccacia', 'Avocado Baguette');$tuesday=array('toast','smoked salmon','caesar salad','chips','chicken parmigaina','fried rice');$wednesday=array('pork spare ribs','lamb with peri peri chips','foccacia', 'Avocado Baguette');$thursday=array('chicken parmigaina','fried rice','gourmet italian pizza','honey pepper chicken');$friday=array('fried rice','gourmet italian pizza','honey pepper chicken','smoked chicken with spinach','pork spare ribs');$days=array('Monday'=>$monday,'Tuesday'=>$tuesday,'Wednesday'=>$wednesday,'Thursday'=>$thursday,'Friday'=>$friday);foreach($days as $key => $value){  //as the key we have the weekday, and the value is the array  echo $key."<br />";    foreach($value as $key2 => $value2)  {    //as the $key2 we have the number of the dish, and as $value we have the dish    echo "<input type=\"radio\" value=\"".$value2."\" /> - ".$value2."<br />";  }	echo "<br />";}?>

I am not too sure if that is what you want to do, but it shows you one possible outcome for your website, or whatever you are doing :)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...