Use count($array) where applicable, instead of a $rowIndex increment.