I didn't test this much, and it won't really work with anything with fewer than 3 point, but this should give you a good starting point.
$curr && $curr < $array[$i + 1]) {
$extremes[] = $curr;
}
//maxes
else if ($last < $curr && $curr > $array[$i + 1]) {
$extremes[] = $curr;
}
if($last != $curr && $curr != $array[$i + 1]) {
$last = $curr;
}
}
//add last point
$extremes[] = $array[$num - 1];
print_r($extremes);
Gives you the results (you missed a couple in your list):
Array
(
[0] => 10
[1] => 8
[2] => 9
[3] => 4
[4] => 11
[5] => 10
[6] => 30
[7] => 28
[8] => 29
[9] => 1
)
If you want to make it be exactly like you're list, you'll have to apply some smoothing to the data, or some tolerances to the detection.