"moving array element to top in php" Answer’s

0

You can achieve that this way:

$arr = array(
    'a1'=>'1',
    'a2'=>'2'
);

end($arr);

$last_key     = key($arr);
$last_value   = array_pop($arr);
$arr          = array_merge(array($last_key => $last_value), $arr);

/*
    print_r($arr);

    will output (this is tested):
    Array ( [a2] => 2 [a1] => 1 )
*/
Wednesday, March 31, 2021
 
Avicinnian
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share