Forum Moderators: coopster
<?php
$previous = false;
$grouping = false;
$groups = 0;
$myArray = array(1,1,0,1,1,0,1,1,0,1,1,0);
for($i=0,$l=count($myArray);$i<$l;$i++){
if($myArray[$i] && $myArray[$i]===$previous){
$grouping = true;
} else {
if($grouping){
$groups++;
}
$grouping = false;
}
$previous = $myArray[$i];
}
if($grouping){
$groups++;
}
print_r($groups);
?>
function multiple($arr) {
$str = implode($arr, " ");
$str = str_replace(" ", " 0 ", $str);// this will fill NULLs with 0's
$str = str_replace(" ", "", $str);// get rid of spaces
// adding a few 0's around it so we also catch beginning and ending 1's
$tmp = preg_split("|(1+)|U", "0".$str."0", null, PREG_SPLIT_NO_EMPTY);
return COUNT($tmp)-1;
}