count()

From: Date: Sat, 06 Dec 2003 05:27:24 +0000
Subject: count()
Groups: php.general 
Request: Send a blank email to php-general+get-172046@lists.php.net to get a copy of this message
Greetings- I'm have the follwing string called $text and throughout this string I'd like to split this into an array by calling spliti() at the tag called PAGEBREAK. So, I count the array elements starting at 0 and get to 9. When I call count(), I get 11. Could somebody please explain why this is? Thank you. TR ................. <? $text=" aaa[PAGEBREAK] //this is the 0 element bbb[PAGEBREAK] //[1] ccc[PAGEBREAK] //[2] ddd[PAGEBREAK] //[3] eee[PAGEBREAK] //[4] fff[PAGEBREAK] //[5] ggg[PAGEBREAK] //[6] hhh[PAGEBREAK] //[7] iii[PAGEBREAK] //[8] jjj[PAGEBREAK] //...and this is the 9th element "; $regexp="\[PAGEBREAK]"; $textarray=spliti($regexp,$text); $num_array=count($textarray); $another_num_array=count($textarray)-1; echo "There are ".$num_array." elements using the count() function.<br>"; echo "If I subtract 1 since elements begin at 0, there are ".$another_num_array."."; //This is the output using count(): //............... //There are 11 elements using the count() function. //If I subtract 1 since elements begin at 0, there are 10 ?>

« previous php.general (#172046) next »