note 108071 deleted from function.array-keys by danbrown

From: Date: Tue, 27 Mar 2012 15:33:51 +0000
Subject: note 108071 deleted from function.array-keys by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-186851@lists.php.net to get a copy of this message
Note Submitter: Roman Horvath ---- Sometimes I am fascinated, how people write code without bothering of memory needs or computing complexity. Want last element key? Just create a new array and pop the last element: array_pop(array_keys($array)); It is okay for small arrays, but consider that you have an array with hundreds of elements... Then I think this is not the most effective way. What about this piece of code: <?php // Get the key of last element end($array); $last_key = key($array); ?> Disadvantage: the internal array pointer is moved to the end...

« previous php.notes (#186851) next »