Re: perl developer struggling with some php concepts

From: Date: Tue, 19 Dec 2000 23:12:39 +0000
Subject: Re: perl developer struggling with some php concepts
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-31076@lists.php.net to get a copy of this message
Yeah, as the code example below shows sizeof does not work in that way. This is on the $testarray = array( "one" , "two" , "three" ); sizeof($testarray) // returns 3 $testarray[9] = "nine"; sizeof($testarray) // returns 4 I want it to return 10. is that possible. basically I'd like empty values placed in the range between indexes. Toby Butzon wrote:
There is such a method. sizeof($thisArray) will always return the number of elements in an array (not the number assigned; ie, "0" and "" are still counted). Since indexing begins at 0 but natural counting begins at 1, simply subtract 1 from the result sizeof() returns and you have the highest index of the array. Toby Butzon [ criticism spurs improvement ] ----- Original Message ----- From: "Vincent Stoessel" <vince@idev.com> To: <php-general@lists.php.net> Cc: "Vincent Stoessel" <vince@idev.net> Sent: Tuesday, December 19, 2000 3:50 PM Subject: [PHP] perl developer struggling with some php concepts : Hello, : I'm forwarding this question to the group from a perl developer : trying to grasp array concepts in php vs perl. : : His statement follows: : : : : Something anamolous in php: finding the highest index of an array is
: non-trivial.    There should be some method available that tells what
: the highest index of an array is. In the first example it should be : two, in the second example it should be 12. : : If anyone finds an answer to this, please share it with the group. : This should be pretty basic. : : : http://www.php.net/manual/function.count.php : : Example 1. Count() example : : $a[0] = 1; : $a[1] = 3; : $a[2] = 5; : $result = count ($a); : file://$result == 3, not 2, as there are 3 assigned elements : : $a[2] = 1; : $a[4] = ""; : $a[6] = 5; : $a[8] = 7; : $a[10] = 11; : $a[12] = ""; : $result = count ($a); : // $result == 4, as there are 4 assigned element : : : Thanks in advance. : : -- : Vincent Stoessel vince@idev.com : Internet Applications Engineer : IDEV http://www.idev.com : : : -- : PHP General Mailing List (http://www.php.net/) : To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net : For additional commands, e-mail: php-general-help@lists.php.net : To contact the list administrators, e-mail: php-list-admin@lists.php.net : :


« previous php.general (#31076) next »