note 100667 added to function.array-reverse
| From: | martyniuk dot vasyl at gmail dot com | Date: | Thu, 28 Oct 2010 21:01:49 +0000 |
| Subject: | note 100667 added to function.array-reverse | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173581@lists.php.net to get a copy of this message | ||
alfbennett at gmail dot com you example will not work if numeric keys are used. This is my proposed
solution:
<?php
$a = array ('x' => 'a', 10 => 'b', 'c', 45 =>
'd'); //array for test
/*
* reverse keys function
*/
function array_reverse_keys($ar){
return array_reverse(array_reverse($ar,true),false);
}
print_r($a);
/*
Array
(
[x] => a
[10] => b
[11] => c
[45] => d
)
*/
print_r(array_reverse_keys($a));
/*
Array
(
[x] => a
[0] => b
[1] => c
[2] => d
)
*/
print_r(array_combine(array_reverse(array_keys($a)),$a));
/*
Array
(
[45] => a
[11] => b
[10] => c
[x] => d
)
*/
?>
----
Server IP: 88.81.245.102 (proxied: 91.196.196.205 1.0 localhost.ua.elro.com:3128
(squid/2.7.STABLE7))
Probable Submitter: 91.202.241.224
----
Manual Page -- http://www.php.net/manual/en/function.array-reverse.php
Edit -- https://master.php.net/note/edit/100667
Del: integrated -- https://master.php.net/note/delete/100667/integrated
Del: useless -- https://master.php.net/note/delete/100667/useless
Del: bad code -- https://master.php.net/note/delete/100667/bad+code
Del: spam -- https://master.php.net/note/delete/100667/spam
Del: non-english -- https://master.php.net/note/delete/100667/non-english
Del: in docs -- https://master.php.net/note/delete/100667/in+docs
Del: other reasons-- https://master.php.net/note/delete/100667
Reject -- https://master.php.net/note/reject/100667
Search -- https://master.php.net/manage/user-notes.php