function summaryRanges($array) {
$ranges = [];
for ($i = 0; $i < sizeof($array); $i++) {
if (isset($array[$i+1]) AND ($array[$i]+1 == $array[$i+1])) {
if (isset($range)) {
$range[] = $array[$i+1];
}
else {
$range = [$array[$i], $array[$i+1]];
}
}
else {
if (isset($range)) {
$ranges[] = $range;
unset($range);
}
}
}
return $ranges;
}
print_r(summaryRanges([110, 111, 112, 113, 1,2,3, 100, 101, 102, 111, -5, -4, -3, -2, -3, -4, -5]));
$date_today = strtotime(date('Y-m-d'));
$iproducts = $date = array();
foreach ($products as $product) {
for ($i = 0; $i <= 11; $i++) {
if (timeInDate($product['created']) === ($date_today-86400*$i)) {
if (array_key_exists($i, $iproducts)) {
$iproducts[$i]++;
}
else {
$iproducts[$i] = 1;
}
}
}
}
for ($i = 0; $i <= 11; $i++) {
if (array_key_exists($i, $iproducts)) {
$date[] = array($date_today-86400*$i => $iproducts[$i]);
}
}
echo '<pre>';
print_r($date);
echo '</pre>';