Re: perl developer struggling with some php array concepts

From: Date: Tue, 19 Dec 2000 23:26:14 +0000
Subject: Re: perl developer struggling with some php array concepts
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31083@lists.php.net to get a copy of this message
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.
All arrays in PHP are, by definition, hashes. As such the concept of first and last elements is essentially meaningless. count(), and its alias sizeof(), returns the number of current elements, not the last element. $A[] = "aa"; $A[] = "bb"; $A[] = "cc"; $A["abc"] = "abc"; $A["xyz"] = "xyz"; $A[10] = "10"; foreach ($A as $Key=>$Value) { echo "<BR>$Key=$Value\n"; } lists the elements in the order in which they were entered. Any assignment in the form of $A[] will use the next highest numeric index, ignoring any gaps in values. $A[] = "new"; would use index 11 in the above example. Urb

« previous php.general (#31083) next »