PHP: Move associative array element to beginning of array

前端 未结 6 460
轮回少年
轮回少年 2020-12-12 17:02

What would be the best method of moving any element of an associative array to the beginning of the array?

For example, say I have the following array:



        
6条回答
  •  爱一瞬间的悲伤
    2020-12-12 17:31

    Here's another simple one-liner that gets this done using array_splice():

    $myArray = array_splice($myArray,array_search('one',array_keys($myArray)),1) + $myArray;
    

提交回复
热议问题