Drop-down list with foreach loop PHP

advertisements

I'm trying to make a drop down list with PHP using a foreach loop to loop through the data. This works without a drop down when I was displaying the results in a table so the loop does work.

It seems the drop down list gets populated (as the list expands/contracts when I've added new fields in for testing) but no data is actually shown. I only need to show one field, though. Here's my code:

    <select name="language_select">
        <?php foreach($this->getContent('languages') as $language => $value) : ?>
            <option value="<?($language['name']);?>"></option>
        <?php endforeach ?>
    </select>

So it fetches an array and tries to return the data, pretty simple. What am I doing wrong?


I'm not to sure of the composition the return of $this->getContent('languages') but I think this is what you need.

<select name="language_select">
    <?php foreach($this->getContent('languages') as $language) : ?>
        <option value="<?= urlencode($language['name']);?>"><?= htmlspecialchars($language["name"]) ?></option>
    <?php endforeach ?>
</select>