Array offset without losing values After looking through PHP.net documentation for hours, is this the best way to offset an array from start to finish by using array_slice() with array_merge()?

For example: $array = array(1,2,3,4) to offset by 2 to get return $array = array(3,4,1,2).

Here's the code I'm using it in:

    $team = 2;
    $course = array(
    array('title'=&gt;1,  'hole'=&gt; 'h01', 'shot1'=&gt;'value="-3"', 'shot2'=&gt;'value="-2"', 'shot3'=&gt;'value="-1"', 'shot4'=&gt;'value="0"', 'shot5'=&gt;'disabled="disabled"'),
    array('title'=&gt;2,  'hole'=&gt; 'h02', 'shot1'=&gt;'value="-4"', 'shot2'=&gt;'value="-3"', 'shot3'=&gt;'value="-2"', 'shot4'=&gt;'value="-1"', 'shot5'=&gt;'value="0"'),
    array('title'=&gt;3,  'hole'=&gt; 'h03', 'shot1'=&gt;'value="-3"', 'shot2'=&gt;'value="-2"', 'shot3'=&gt;'value="-1"', 'shot4'=&gt;'value="0"', 'shot5'=&gt;'disabled="disabled"'),
    array('title'=&gt;4,  'hole'=&gt; 'h04', 'shot1'=&gt;'value="-2"', 'shot2'=&gt;'value="-1"', 'shot3'=&gt;'value="0"', 'shot4'=&gt;'disabled="disabled"', 'shot5'=&gt;'disabled="disabled"'),
    array('title'=&gt;5,  'hole'=&gt; 'h05', 'shot1'=&gt;'value="-4"', 'shot2'=&gt;'value="-3"', 'shot3'=&gt;'value="-2"', 'shot4'=&gt;'value="-1"', 'shot5'=&gt;'value="0"')
    );

    $array1 = array_slice($course, $team);
   $array2 = array_slice($course, 0, $team);
   $merged = array_merge($array1, $array2);

}
If you don't mind modifying the original array, you can shorten the (perfectly adequate code you have) with this:

$head = array_splice($course, 0, $team);  // remove and return first $team elements
$merged = array_merge($course, $head);    // append them to the end


You should be able to omit the temporary $head array by inserting the array_splice call into the array_merge call at the cost of a little code clarity. Try it out to make sure the order of operations is correct.

$merged = array_merge($course, array_splice($course, 0, $team));


Edit: If you're doing this once per team you can use a loop with array_shift to remove the first element and array_push to place it at the end:

for ($team = 0; $team &lt; $numTeams; $team++) {
    array_push($course, array_shift($course));
    // use $course...
}