Better solution to variable argument function?
<p>This is what I have now:</p>

<pre><code> function getAlbum(){
     $args = func_get_args();

     if(!(count($args) % 2) || count($args) == 1) {
         trigger_error('Argument count must be an odd number and greater than one.');
         return false;
     }

     $q = new Query("album_manager");
     $q-&gt;select($args[0]);
     unset($args[0]);
     call_user_func_array(array($q, "where"),$args);
     $q-&gt;limit(1);
     return send_back_as_array($q);
 }
</code></pre>

<p>If you call <code>getAlbum('*','cid',1)</code> you get all attributes where <code>cid=1</code><br>
If you call <code>getAlbum('cid, anchor', 'cid',1)</code> you get the <code>anchor</code> and <code>cid</code> where <code>cid=1</code></p>

<p>It works fine, except I am worried that when someone is debugging the code, they might mistake the <code>,</code> between <code>cid</code> and <code>anchor</code> for an argument separator and get confused.</p>

<p>Does anyone have a more elegant solution? I am just interested.</p>

<p>I thought about changing it to where it accepts <code>getAlbum('cid','anchor','where:','cid',1)</code> but I'm not sure that will be any better.</p>

<p>This is what I changed it to:</p>

<pre><code>function getAlbum(){
    // argument one is a comma separated value or an array of what is requested.
    // the rest of the args must be an even number (odd number of args overall)
    // ever even argument is a selector and every odd is a condition 'selector = condition' in query
    // Examples:
    //      getAlbum('*','cid',1);   &lt;-  Select all attributes from album where cid = 1
    //      getAlbum('cid','anchor','test','name','This is a test'); &lt;- select cid from album where anchor = 'test' and 'name' = 'This is a test'
    //      getAlbum(array('cid','anchor'),'test','name'); select cid and anchor where 'test'='name'
    //      getAlbum('cid, anchor','cid',1); select cid and anchor where cid=1
    $args = func_get_args();
    if(!(count($args) % 2) || count($args) == 1) {
        trigger_error('Argument count must be an odd number and greater than one.');
        return false;
    }
    $q = new Query("album_manager");
    $q-&gt;select((is_array($args[0]) ? implode(", ",$args[0]) : $args[0]));
    unset($args[0]);
    call_user_func_array(array($q, "where"),$args);
    $q-&gt;limit(1);
    $array = send_back_as_array($q);
    if(count($array) != 1) return false;
    else return $array;
}
</code></pre>
