I have an array
array(
'key1'=>'value1',
'key2'=>'value2',
'key3'=>'value3'
)
I want create it like
array(
'key3'=>'value3',
'key1'=>'value1',
'key2'=>'value2'
)
I just want to move the last element to first with key value pair keeping all other details as it is.
simplest way to do with below code
$arr = array(
'key1'=>'value1',
'key2'=>'value2',
'key3'=>'value3'
);
$lastvalue = end($arr);
$lastkey = key($arr);
$arr1 = array($lastkey=>$lastvalue);
array_pop($arr);
$arr1 = array_merge($arr1,$arr);
OUTPUT
Array
(
[key3] => value3
[key1] => value1
[key2] => value2
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With