Quantcast
Channel: Shift one value of array values to the beginning - Code Review Stack Exchange
Viewing all articles
Browse latest Browse all 5

Shift one value of array values to the beginning

$
0
0

Given an integer $value in the range of 1, 2, 3, I want to get an array that starts with $value and proceeds with the remaining two integers from above in arbitrary order. The best I could think of was doing something like this:

switch ($value) {      case '1':        $array = [1,2,3];        break;      case '2':        $array = [2,1,3];        break;      case '3':        $array = [3,1,2];        break;    }

Is there a shorter and more beautiful way of doing that? Something like that:

$array = push_to_top_of_array($value,[1,2,3]);

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles



Latest Images