title: Allowing multiple arguments in any order in PHP
body: <p>I have a function which takes in about 10 arguments, in which most of them are optional. I was wondering if I could implement it in such a way that the user of the function does not need to bother with the order of the parameters.
  For example:</p>
  
  <pre><code>public function foo($arg1, $arg2, $arg3='',$arg4='', $arg5='', $arg6='', $arg7=''){}
  </code></pre>
  
  <p>Now, when I use this function I can simply</p>
  
  <pre><code>$this-&gt;foo($arg1val, $arg2val, $arg6val);
  </code></pre>
  
  <p>Is there a way in php to do so?</p>
  
  <p>Here is how I implemented this:
  I've listed the parameters accepted by the function in the API, so the user can pass the parameters in any order in an array with key=>value pairs.</p>
  
  <p>For example:</p>
  
  <pre><code>public function argumentsFilter($origParams, $newParams){
      $tmpArr = array();
          foreach ($origParams as $origKey){
          foreach($newParams as $newKey =&gt; $newVal){
                      if($newKey == $origKey){
                  $tmpArr[$origKey] = $newVal;
                      }
          }
          if(empty($tmpArr[$origKey])){
                      $tmpArr[$origKey] = '';
          }
             }
          return $tmpArr;
  }
  
  public function foo($arg1, $arg2, $arg=array()){
  
      $validArgList = array('arg3', 'arg4', 'arg5', 'arg6', 'arg7');
  
      $correctedArgList = $this-&gt;argumentsFilter($validArgList, $arg);   
  
  }
  </code></pre>
  
  <p>Is there a more elegant way to do this?</p>