Shift one value of array values to the beginning
Is there a shorter and more beautiful way of doing that?



shorter: yes
more beautiful: well, that sounds subjective... you can be the judge of the approaches below.


One approach would be to take off the value using $index with array_splice() and then put it (the first element from that spliced array) at the beginning using array_unshift():

$array = [1, 2, 3];
array_unshift($array, array_splice($array, $value - 1, 1)[0]);


See it demonstrated in this playground example.

Another approach would be to merge the spliced array and the original array using array_merge():

$array = [1, 2, 3];
$array = array_merge(array_splice($array, $value - 1, 1), $array);


See it demonstrated in this playground example.