use sizeof( $theArray )
Note that for ($i = 0; $i < sizeof($theArray); $i++) lies in O(n) cause of the sizeof and should be replaced with
$myArraySize = sizeof($theArray);
for ($i = 0; $i < $myArraySize; $i++)
you can also iterate over arrays with a for each statement.
see www.php.net for more details