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'=>1, 'hole'=> 'h01', 'shot1'=>'value="-3"', 'shot2'=>'value="-2"', 'shot3'=>'value="-1"', 'shot4'=>'value="0"', 'shot5'=>'disabled="disabled"'),
array('title'=>2, 'hole'=> 'h02', 'shot1'=>'value="-4"', 'shot2'=>'value="-3"', 'shot3'=>'value="-2"', 'shot4'=>'value="-1"', 'shot5'=>'value="0"'),
array('title'=>3, 'hole'=> 'h03', 'shot1'=>'value="-3"', 'shot2'=>'value="-2"', 'shot3'=>'value="-1"', 'shot4'=>'value="0"', 'shot5'=>'disabled="disabled"'),
array('title'=>4, 'hole'=> 'h04', 'shot1'=>'value="-2"', 'shot2'=>'value="-1"', 'shot3'=>'value="0"', 'shot4'=>'disabled="disabled"', 'shot5'=>'disabled="disabled"'),
array('title'=>5, 'hole'=> 'h05', 'shot1'=>'value="-4"', 'shot2'=>'value="-3"', 'shot3'=>'value="-2"', 'shot4'=>'value="-1"', 'shot5'=>'value="0"')
);
$array1 = array_slice($course, $team);
$array2 = array_slice($course, 0, $team);
$merged = array_merge($array1, $array2);
}