PHP has a lot of functions for working with arrays; [man]array_slice[/man] is the first that comes to mind, followed by [man]array_chunk[/man]. [man]reset[/man] and [man]end[/man] also give the first and last elements of an array. There's also a trick mentioned in the user notes on [man]array_map[/man] that can come in handy.
To get every fifth element of an array, as well as the first and last elements
$first_element = reset($array);
$last_element = end($array);
$array_sections = array_chunk($array, 5);
// Transpose (see user notes in array_map)
$array_sections = array_unshift($array_sections, null);
$array_sections = call_user_func_array('array_map', $array_sections);
// Just the first elements of each section
$sampled_array = array_map('reset', $array_sections);
// We already have the first element - don't want to repeat it
array_shift($sampled_array);
// We don't want to repeat the last element either.
if(count($array) % 5 == 1)
{
array_pop($sampled_array);
}
array_unshift($sampled_array, $first_element);
array_push($sampled_array, $last_element);
(Note: totally untested.)