By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

Select list help

P: 5
I want to create the following print_r results into a dynamic select list.. I have tried something like:

[PHP]<?php $prefixes = array(explode("\n", $board['topic_prefix_label']));

echo '<select name="tprefix">';
for($i = 0; $i < count($prefixes); $i++)
echo '<option value="'.$i.'">'.$prefixes[$i].'</option>';

echo '</select>';?>[/PHP]

But it just says array as I should've expected..

When I use:

[PHP] print_r(explode("\n", $board['topic_prefix_label']));[/PHP]

I get: Array ( [0] => Fun: [1] => Games: [2] => Stuff: )

And it is those that I wish to have in my select list.. any idea how to do this?

Oct 19 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 4,258
Kirkingly: welcode to TSDN!

$prefixes is a 2-dim array where only the first entry (0) is used.
So your code should address the $prefixes[0] array to extract the values:
for($i = 0; $i < count($prefixes[0]); $i++)
echo '<option value="'.$i.'">'.$prefixes[0][$i].'</option>';
Oct 19 '07 #2

P: 5
Thank you!

Works amazingly.. I didn't realise I had to have the 0, I am learning

Thanks a lot,
Oct 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.