Jump to content

Foreach and DropDownList


christa

Recommended Posts

hi friends!

 

this code

foreach ( $users as $key => $value ) {
    $user_ids = implode(',', $value);
    echo "$key - $user_ids<br />";
}

 

sends this output:

user one - 376,373
user charlie -
user beta - 372

 

I need the $user_ids are shown in a DropDownList, of course only if the $user_ids is not empty. How can I do? thanks!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/260551-foreach-and-dropdownlist/
Share on other sites

The html select tag makes a dropdown list.

 


  Display in list

 

So you simply need to build the options in your foreach and echo out the data in the option tag. 

 

echo '';
foreach ( $users as $key => $value ) {
    $user_ids = implode(',', $value);
    if (!empty($user_ids)) {
        echo "$user_ids";
    }
}
echo '';

 

 

Archived

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

×
×
  • Create New...

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.