PHP count()


count() returns the total elements number of an array.

<?PHP
	$arr=array(1,2,3,4,5,6,7,8,9);
    $len=count($arr);
	echo "$len";  //9
?>

count() is frequently used to loop through an array.
<?PHP
	$arr=array(1,2,3,4,5,6,7,8,9);
	for ($ii=0;$ii<count($arr);$ii++)
	{
	    echo "$ii, $arr[$ii]\n";
	}
	/*
	0, 1
	1, 2
	2, 3
	3, 4
	4, 5
	5, 6
	6, 7
	7, 8
	8, 9
	*/
?>