count of false gives 1 and if of an empty array gives false. why?
<p>I have a function which returns only one row as array.</p>

<p>I give a query as a parameter which will exactly gives only one row.</p>

<pre><code>function getFields($query)
{
    $t =&amp; get_instance(); 
    $ret = $t-&gt;db-&gt;query($query);
    if(!$ret)return false;
    else if(!$ret-&gt;num_rows()) return array();
    else return $ret-&gt;row_array();
}
$ret = getFields('query string');
</code></pre>

<p>What i thought was ...</p>

<ol>
<li>if there is an error then i can check it like if(!$res)//echo error</li>
<li>if it is empty i can check it like if(!count($res))// no rows</li>
<li>else i assume that there is a row and continue the process...</li>
</ol>

<p>BUT</p>

<ol>
<li>when there is an error false is returned. In if(count($ret)) gives 1.</li>
<li>If($ret) conditions fails (gives false) if i return as empty array.</li>
</ol>

<p>//</p>

<pre><code>$ret = getFields('query string');
if(!$fes)jerror('status,0,msg,dberror');        
if(!count($fes))jerror('status,1,msg,no rows');     
// continue execution when there atleast one row.
</code></pre>

<p>this code is called using ajax. so i return a json response.</p>

<p>why count gives 1 and if empty array gives false.</p>

<p><strong>i just wanted to code with logical conditions instead of giving more relations conditions. just to reduce code.</strong></p>

<p>Where can i get all these BUGGING stuff of php so that i can make sure i should not end up making logical errors like the above.</p>

<blockquote>
  <p>BUGGING - in the above sentence
  bugging i referred as not a bug but
  things bugs us. things which makes us
  logical errors.</p>
</blockquote>

<hr>

<hr>

<p><em>I edited this following code to include the following meanwhile i got this as the reply by <a href="http://stackoverflow.com/users/451672/andrew-dunn">http://stackoverflow.com/users/451672/andrew-dunn</a></em></p>

<p>i can do it like this but still i want to know why for the above explanation</p>

<pre><code>if($fes===false)jerror();
if(!$fes)jsuccess('status,4');      
</code></pre>
