Jump to content

Archived

This topic is now archived and is closed to further replies.

play_

Quick dropdown menu help

Recommended Posts

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

[code]$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>';
}
}[/code]

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

Share this post


Link to post
Share on other sites
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:
[code]<?php

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

?>[/code]


Orio.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.