使用目录填充选择框

I have the following code. I'm looking to do what's in the comment which is to populate a selectbox with a name of directories. How would I do that?

$path = 'repository/' . $name[0];
$results = scandir($path);

foreach ($results as $result) {
if ($result === '.' or $result === '..') continue;

if (is_dir($path . '/' . $result)) {
    //extract directory names and populate selectbox
  }
}

At maybe its simplest:

echo "<select name=\"something\">";
foreach(glob("repository/{$name[0]}/*", GLOB_ONLYDIR) as $dir) {
    echo "<option>$dir</option>";
}
echo "</select>";

A quick and dirty solution, assuming result is the directory you want to show:

echo '<select id="directories" name="directories">';
foreach ($results as $result) {
if ($result === '.' or $result === '..') continue;

if (is_dir($path . '/' . $result)) {
    echo '<option value="' . $result . '">' . $result . '</option>';
  }
}
echo '</select>';

Perhaps I've not understood the question but surely it's just:

<?php

$selectString = '<select>';

$path = 'repository/' . $name[0];
$results = scandir($path);

foreach ($results as $result) {
    if ($result === '.' or $result === '..') {
        continue;
    }

    if (is_dir($path . '/' . $result)) {
        $selectString .= "<option>{$result}</option>";
    }
}
$selectString .= "</select>"

You can then put $selectString wherever you need it.