Jump to content


Photo

Quick dropdown menu help


  • Please log in to reply
2 replies to this topic

#1 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 14 October 2006 - 05:04 PM

I have an array and i`d like to make a dropdown from that array

$pages = array("Home" => "home.html", "About" => "about.html", "Crew" => "crew.html");
		$arraysize = count($pages);
		for($i = 0; $i <= $arraysize; $i++) {
			foreach($key as $value) {
				echo '<option value="$key">$value</option>';
			}
		}

That's what i have, but it isn't working. any ideas?

regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 14 October 2006 - 05:22 PM

Your foreach statement is wrong.
It should be:
foreach($pages as $key => $value)

Also, you dont need the for loop, because the foreach does the work for you.

Final code should look like:
<?php

$pages = array("Home" => "home.html", "About" => "about.html", "Crew" => "crew.html");
foreach($pages as $key => $value)
	echo '<option value="'.$key.'">'.$value.'</option>';

?>


Orio.
Think you're smarty?

(Gone until 20 to November)

#3 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 14 October 2006 - 06:58 PM

many thanks
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users