title: how arguments are passed to codeigniter method
body: <p>I have a method in a codeigniter controller which is sometimes called through the url and sometimes called internally from another method of the controller.  When I call it internally I pass an array of arguments.  Simplified version of method:</p>
  
  <p>(within a controller)</p>
  
  <pre><code>function get_details($args='') {
  
      if (isset($args['first_name'])) 
      {
          $first_name = $args['first_name'];
      } 
      else
      {
          $first_name = $this-&gt;uri-&gt;segment(3);
      } 
  
      ... do some other stuff ...
  
  }
  </code></pre>
  
  <p>The method is either called  as:</p>
  
  <pre><code>&lt;domain&gt;/&lt;controller&gt;/get_details/abcd/efgh 
  </code></pre>
  
  <p>or from another function of the controller as:</p>
  
  <pre><code>$this-&gt;get_details(array('first_name'=&gt;'abcd', 'last_name'=&gt;'efgh'));
  </code></pre>
  
  <p>I was expecting that when the method was called through the url, isset($args['first_name']) would be false, however it seems that called in this way the argument is there.  I tried printing a couple of things and this is what I got:</p>
  
  <pre><code>print_r($args)  ----&gt;   abcd
  
  echo($args['first_name'])  ----&gt; a
  
  echo($args['whatever_index_I_use'])  ----&gt; a  
  </code></pre>
  
  <p>It seems like the third parameter of the url is being passed into the method (by codeigniter?), but can't work out why the array indexes seem to be set, all I can think is that php is converting the string to an int, so <code>$args['whatever_index_I_use'], becomes $args[0]</code>??</p>
  
  <p>Not sure if this is a codeigniter thing or me missing a subtlety of php.</p>
  
  <p>Much appreciate anyone who can explain what's going on.</p>
  
  <p>Thanks.</p>