note 95299 added to function.array-keys
| From: | kurtz8763 at gmail dot com | Date: | Fri, 25 Dec 2009 02:28:23 +0000 |
| Subject: | note 95299 added to function.array-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164314@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 76.247.173.69
----
Manual Page -- http://www.php.net/manual/en/function.array-keys.php
Edit -- https://master.php.net/note/edit/95299
Del: integrated -- https://master.php.net/note/delete/95299/integrated
Del: useless -- https://master.php.net/note/delete/95299/useless
Del: bad code -- https://master.php.net/note/delete/95299/bad+code
Del: spam -- https://master.php.net/note/delete/95299/spam
Del: non-english -- https://master.php.net/note/delete/95299/non-english
Del: in docs -- https://master.php.net/note/delete/95299/in+docs
Del: other reasons-- https://master.php.net/note/delete/95299
Reject -- https://master.php.net/note/reject/95299
Search -- https://master.php.net/manage/user-notes.php