note 100667 deleted from function.array-reverse by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Oct 2010 21:03:17 +0000 |
| Subject: | note 100667 deleted from function.array-reverse by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173583@lists.php.net to get a copy of this message | ||
Note Submitter: martyniuk dot vasyl at gmail dot com
----
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
)
*/
?>