Stack Exchange
echo count & echo sizeof showing wrong count
I have this query 
$status = 'failed';
$allTest = $conn->prepare('SELECT SUM( IF( STATUS = :status, 1, 0 ) ) FROM tooldata WHERE testCase REGEXP :var GROUP BY family ORDER BY family' );
$allTest->execute(array(':status' => $status, ':var' => "^$var"));

while($row = $allTest->fetch(PDO::FETCH_ASSOC))
    { 
    foreach($row as $key) 
        {
            $totalTestFailed[] = $key;
        } 
    }

if( (null == $totalTestFailed[0]) || (0 == $totalTestFailed[0]) )
    {
        array_shift($totalTestFailed);
    }

the output of the array_shift($totalTestFailed) is 
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 0 [4] => 1 [5] => 1 [6] => 2 [7] => 0 [8] => 0 [9] => 2 [10] => 1 [11] => 1 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 4 [17] => 0 [18] => 0 [19] => 0 [20] => 20 )

now when I do echo sizeof($totalTestFailed);  I get 22 instead of 21
whereas with var_dump , I get array (size=21)
What is wrong here ?

Try to first save shitfted array in variable and then count that variable

@Mpa4Hu I even tried that but still it returns 22 -
foreach ($totalTestIncomplete as $key)   { $new[] = $key; } echo sizeof($new);

This is what documentation says:  

array_shift() shifts the first value of the array off and returns it.

It does not modify array but returns modified array.
You need to save that variable and then count that variable.
Or you can do something like this:  
$totalTestFailed = array_shift($totalTestFailed);
echo sizeof($totalTestFailed);

