Why can't I have duplicate working functions?
<p>I have a config page I am creating in PHP, I have used some code I found to create a dropdown from files found in a folder </p>

<pre><code> &lt;?php 

$folder = '../Pic/Upload'; 

echo '&lt;select name="sabpic"&gt;'."\n". 
     dropdown(image_filenames($folder), @$_POST['image']). 
     '&lt;/select&gt;'."\n".'&lt;/br&gt;&lt;/br&gt;'; 

function image_filenames($dir) 
{ 
    $handle = @opendir($dir) 
        or die("I cannot open the directory '&lt;b&gt;$dir&lt;/b&gt;' for reading."); 
    $images = array(); 
    while (false !== ($file = readdir($handle))) 
    { 
        if (eregi('\.(jpg|gif|png)$', $file)) 
        { 
            $images[] = $file; 
        } 
    } 
    closedir($handle); 
    return $images; 
} 

function dropdown($options_array, $selected = null) 
{ 
global $sabpicname;
    $return = null; 
    foreach($options_array as $option) 
    { 
        $return .= '&lt;option value="'.$option.'"'. 
                   (($option == $sabpicname) ? ' selected="selected"' : null ). 
                   '&gt;'.$option.'&lt;/option&gt;'."\n"; 
    } 
    return $return; 
} 

?&gt;
</code></pre>

<p>Now this works perfectly for "selecting a picture for SAB" and when the page is loaded reads the value in $sabpicname and selects that option as default as expected.</p>

<p>I assumed I could take that same function and modify the $sabpicname to $sickpicname and it would work the same but select the value that was contained in the variable instead..</p>

<pre><code>&lt;?php 

echo '&lt;select name="sickpic"&gt;'."\n". 
     dropdown(image_filenames($folder), @$_POST['image2']). 
     '&lt;/select&gt;'."\n".'&lt;/br&gt;&lt;/br&gt;'; 

function dropdown_sick($options_array, $selected = null) 
{ 
global $sickpicname;
    $return2 = null; 
    foreach($options_array as $option2) 
    { 
        $return2 .= '&lt;option value="'.$option2.'"'. 
                   (($option2 == $sickpicname) ? ' selected="selected"' : null ). 
                   '&gt;'.$option2.'&lt;/option&gt;'."\n"; 
    } 
    return $return2; 
} 

?&gt;
</code></pre>

<p>But no matter what I seem to do, this second dropdown is still taking the selected value that is stored in $sabpicname and not $sickpicname, but from what I can see, its now a seperate function and doesn't reference the $sabpicname variable atall, it's not working, so I'm obviously missing something..</p>

<p>Hope someone can shine some light on what im doing wrong.</p>