note 95299 deleted from function.array-keys by danbrown

From: Date: Fri, 25 Dec 2009 03:37:08 +0000
Subject: note 95299 deleted from function.array-keys by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164315@lists.php.net to get a copy of this message
Note Submitter: kurtz8763 at gmail dot com ---- Re: Sven (bitcetera.com) on 19-Dec-2005 02:43 Unfortunately all of those array functions are passed by reference, so you now get a "Strict Standards" warning for trying to modify the return value of reference-enabled functions. To fix this use non destructive methods like current() and array_reverse() to achieve the same effect: <?php $array = array('first'=>'111', 'second'=>'222', 'third'=>'333'); // get the first key: returns 'first' printf("First Key: %s\n", current(array_keys($array))); // get the last key: returns 'third' printf("Last Key: %s\n", current(array_reverse(array_keys($array)))); // get the first value: returns '111' printf("First Val: %d\n", current(array_values($array))); // get the last value: returns '333' printf("Last Val: %d\n", current(array_reverse(array_values($array)))); ?> Outputs: First Key: first Last Key: third First Val: 111 Last Val: 333

« previous php.notes (#164315) next »