note 108071 added to function.array-keys

From: Date: Tue, 27 Mar 2012 02:40:44 +0000
Subject: note 108071 added to function.array-keys
Groups: php.notes 
Request: Send a blank email to php-notes+get-186828@lists.php.net to get a copy of this message
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... ---- Server IP: 69.147.83.197 Probable Submitter: 193.110.186.106 ---- Manual Page -- http://www.php.net/manual/en/function.array-keys.php Edit -- https://master.php.net/note/edit/108071 Del: integrated -- https://master.php.net/note/delete/108071/integrated Del: useless -- https://master.php.net/note/delete/108071/useless Del: bad code -- https://master.php.net/note/delete/108071/bad+code Del: spam -- https://master.php.net/note/delete/108071/spam Del: non-english -- https://master.php.net/note/delete/108071/non-english Del: in docs -- https://master.php.net/note/delete/108071/in+docs Del: other reasons-- https://master.php.net/note/delete/108071 Reject -- https://master.php.net/note/reject/108071 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186828) next »