$e = count($d) - 1;
$f = false;
$g = 0;
$h = 0;
if ($c < 0) {
$c = -$c;
$f = true;
}
$i = 2 / (2 + $c);
$j = 4 * $i - 2;
for (; $e > 0; $e--) {
$k = $g;
$g = $j * $g - $h + $d[$e];
$h = $k;
}
$l = $i * exp(-$c * $c + 0.5 * ($d[0] + $j * $g) - $h);
return $f ? ($l - 1) : (1 - $l);
$openingHours = [
['day' => 'monday', 'time' => '08:00-20:00'],
['day' => 'tuesday', 'time' => '08:00-20:00'],
['day' => 'wednesday', 'time' => '08:00-23:59'],
['day' => 'thursday', 'time' => '08:00-20:00'],
['day' => 'friday', 'time' => '08:00-20:00'],
['day' => 'saturday', 'time' => '10:00-16:00'],
['day' => 'sunday', 'time' => '10:00-16:00'],
];
$result = $active = [];
$openingHours[] = ['day' => '', 'time' => '']; // empty value to simplify code
foreach ($openingHours as $openingHour) {
if ($active) {
if ($active['time'] === $openingHour['time']) {
$active['end'] = $openingHour['day'];
} else {
$key = $active['end'] ? $active['start'] . '-' . $active['end'] : $active['start'];
$result[$key] = $active['time'];
$active = [];
}
}
$active = $active ?: [
'time' => $openingHour['time'],
'start' => $openingHour['day'],
'end' => null,
];
}
print_r($result);
$openingHours = [
['day' => 'monday', 'time' => '08:00-20:00'],
['day' => 'tuesday', 'time' => '08:00-20:00'],
['day' => 'wednesday', 'time' => '08:00-20:00'],
['day' => 'thursday', 'time' => '10:00-20:00'],
['day' => 'friday', 'time' => '10:00-18:00'],
['day' => 'saturday', 'time' => '10:00-16:00'],
['day' => 'sunday', 'time' => '10:00-16:00'],
];
$temp = array();
$result = array();
foreach($openingHours as $key => $item) {
$temp[$item['time']][] = $item['day'];
}
foreach($temp as $key => $item){
$count = count($item) -1;
$count >= 1 ? $result[$item[0].'-'.$item[$count]] = $key : $result[$item[0]] = $key;
}
print_r($result);
Array
(
[monday-wednesday] => 08:00-20:00
[thursday] => 10:00-20:00
[friday] => 10:00-18:00
[saturday-sunday] => 10:00-16:00
)
//...
class Order extends Model
{
protected static function boot()
{
parent::boot();
static::addGlobalScope('owner', function (Builder $builder) {
$user = Auth::user();
if (! $user->isAdmin()) {
$builder->where('user_id', $user->id);
}
});
}
}