Mine's similar to jprofitt's
but I divided them into peaks and valleys, so I can do some more stuff with it.
I think his loop is much more cleaner than mine is, but I just wanted to test it out for myself.
Don't judge meeeeee
This script just plots the points out and selects the peaks and valleys and give them green and red respectively. See it as a visual aid. :P
$array[$i-1];
$more_than_next = $array[$i] > $array[$i+1];
$next_is_equal = $array[$i] == $array[$i+1];
if($next_is_equal) continue;
if($i == 0){
if($more_than_next){
$peaks[] = $array[$i];
$peak_keys[] = $i;
}else{
$valleys[] = $array[$i];
$valley_keys[] = $i;
}
}elseif($i == (count($array)-1)){
if($more_than_last){
$peaks[] = $array[$i];
$peak_keys[] = $i;
}else{
$valleys[] = $array[$i];
$valley_keys[] = $i;
}
}else{
if($more_than_last && $more_than_next){
$peaks[] = $array[$i];
$peak_keys[] = $i;
}elseif(!$more_than_last && !$more_than_next){
$valleys[] = $array[$i];
$valley_keys[] = $i;
}
}
}
return array("peaks" => $peaks, "valleys" => $valleys, "peak_keys" => $peak_keys, "valley_keys" => $valley_keys);
}
?>
";
foreach($plot as $key => $point){
$left = ($key*10);
$top = 400 - ($point*10);
if(in_array($key, $res['peak_keys']) || in_array($key, $res['valley_keys'])){
$extreme = "$point
";
}else{
$extreme = "";
}
if(in_array($key, $res['peak_keys'])){
$xc = "extr_high";
}elseif(in_array($key, $res['valley_keys'])){
$xc = "extr_low";
}else{
$xc = "";
}
echo "$extreme
";
}
echo "
";
?>