Re: [PHP4BETA] no reverse fetch of arrays is BAD!

From: Date: Wed, 23 Feb 2000 14:17:43 +0000
Subject: Re: [PHP4BETA] no reverse fetch of arrays is BAD!
References: 1 2 3  Groups: php.version4 
Request: Send a blank email to php-version4+get-10723@lists.php.net to get a copy of this message
On Wed, 23 Feb 2000, Faisal Nasim wrote: > But, there is a major diff b/w perl and php: > > perl: $x[10] = "test"; // size of @x is 11 > php: $x[10] = "test"; // size of $x is 1 > > Which creates a new question: > > Is there a way to detect the upper bound of an array? It behooves everyone to know how PHP arrays are handled. When you say $x[10] = "test", PHP does not allocate 11 memory blocks and fill the last one in. It simply uses a hash to store the "test" with numeric index 10. Thus only one block is allocated and only one value is stored. Much more efficient. Now, to answer your question, one way would be max(array_keys($x)) which would give you back the maximum key. The problem comes in when you start mixing numeric and string keys... -Andrei "When I get a little money, I buy books; and if any is left I buy food and clothes." -- Erasmus

« previous php.version4 (#10723) next »