Reputation: 1737
I have an array array(1=>'randstring1', 2=>'randstring2', 3=>'randstring3', 4=> 'randstring4')
I want to reverse or sort the key from 4 to 1 while preserving the value so it would be like
Array(
[4] => randstring1
[3] => randstring2
[2] => randstring3
[1] => randstring4
)
Upvotes: 1
Views: 528
Reputation: 12332
A combination of array_combine, array_reverse and array_keys should do the trick.
$newArray = array_combine( array_reverse( array_keys( $array ) ), $array );
Upvotes: 5