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

From: Date: Wed, 23 Feb 2000 15:00:48 +0000
Subject: Re: [PHP4BETA] no reverse fetch of arrays is BAD!
References: 1 2 3 4  Groups: php.version4 
Request: Send a blank email to php-version4+get-10728@lists.php.net to get a copy of this message
: > 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. But still it will be string in nature (that 10, I assume), and you'd lookup: $array [10] in a linked list or whatever through strcmp (or some custom function, memcmp perhaps...) which will be slower compared to numeric lookup as in a plain, old-fashioned array.... wouldn't it? You can do the same thing in perl with associative arrays, but there are plain arrays too, which are alot faster! : : 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... Can't we have a nice type which makes an array truly numerical? And would give an error when you try add a non-numerical (actually positive integer) value? (as I see that rewriting another model for plain arrays can break A LOT of things!) Suggestion: settype ( $MYARRAY , "numericarray" ) : : -Andrei : : "When I get a little money, I buy books; : and if any is left I buy food and clothes." -- Erasmus This quotes fits me the best! But I saw it first on a bookmark I got with my Applied Cryptography book from Amazon. Enjoy! Faisal

« previous php.version4 (#10728) next »