title: Why isn't CodeIgniter taking certain variables as the third argument to form_dropdown()?
body: <p>My form is set up to load values from a database (which I've passed via the template engine) on first load, and from POSTed values on subsequent loads if a validation fails. For instance, things like this work fine:</p>
  
  <pre><code> $title = array(
                'name'        =&gt; 'aboutme',
                'id'          =&gt; 'aboutme',
                'value'       =&gt; set_value('aboutme','{about_me}'),
                'rows'        =&gt; '20',
                'cols'        =&gt; '64'
              );
  </code></pre>
  
  <p>But I'm stumbling on form_dropdown.</p>
  
  <pre><code>$ethnicity_array = array('Please choose', 'Asian', 'Black', 'Hispanic / Latin',  'Native American', 'Pacific Islander', 'Southeast Asian', 'White', 'Mixed', 'Other');
  
  echo form_dropdown('ethnicity', $ethnicity_array,set_value('ethnicity','{ethnicity}'));
  </code></pre>
  
  <p>It doesn't generate the HTML to mark a choice as selected.</p>
  
  <p>Even this fails:</p>
  
  <pre><code>$var = set_value('ethnicity','{ethnicity}');
  
  echo $var;     // verify that it has the expected value, let's say 7
  
  echo form_dropdown('ethnicity', $ethnicity_array,$var);
  </code></pre>
  
  <p>This also fails -- that is, it doesn't generate the proper HTML to mark the corresponding option as selected:</p>
  
  <pre><code>echo form_dropdown('ethnicity',$ethnicity_array,(isset($_POST['ethnicity']) ? $_POST['ethnicity'] : $var));
  </code></pre>
  
  <p>But, THIS works:</p>
  
  <pre><code>echo form_dropdown('ethnicity', $ethnicity_array,7);
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>$var = 7;
  
  echo form_dropdown('ethnicity', $ethnicity_array,$var);
  </code></pre>
  
  <p>It seems like it's some sort of type casting issue, so maybe it's just something I fundamentally don't understand about PHP.</p>
  
  <p>Update: it may be a typecasting issue. Trying this:</p>
  
  <pre><code>$var = "{ethnicity}";
  
  echo var_dump($var);
  
  $iv = intval($var);
  
  echo "&lt;div&gt;IV:&lt;/div&gt;";
  
  echo var_dump($iv);
  </code></pre>
  
  <p>Yields:</p>
  
  <p>string(15) "7"
  IV:
  int(0)</p>
  
  <p>I have no clue why intval() is return 0 for the string "7". I've looked at other questions about intval() here on stackoverflow and now I'm even more confused. But if form_dropdown is also trying an int conversion and it's failing, that might be the problem.</p>