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]);
$array
used after this code? would there ever be a case where other values would exist in that array? \$\endgroup\$foreach
loop. There is no case where other values would exist. \$\endgroup\$foreach
loop do with it? Can you describe the output of the script? For code review, it is best to have a broad picture of what the code does. \$\endgroup\$