<?php
if (10 <= date("G") && date("G") <= 20) {
echo "сейчас на сервере от 10 до 20 часов.";
}
<?php
$commands = [
'hi' => fn($name) => 'hi, ' . $name,
'hello' => fn($name) => 'hello , ' . $name,
'etc' =>fn($name) => 'etc...',
];
echo $commands['hi']('John');
<?php
$arr = [1, 3, 4, 6, 4, 2, 1, 1];
$res1 = array_count_values($arr);
//var_export($res1);
$res2 = array_filter($res1, fn($el)=>($el>1));
var_export(array_keys($res2));
json_encode(
[ 'Цена' => intval($_GET['price'] * 100 )/100 ],
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
);
<?php
$date = date('Y-m-01');
$next_month = date('Y-m-d', strtotime('+1 month', strtotime($date)));
function nextWorkDay($date) {
$day_of_week = date('N', strtotime($date));
if ($day_of_week>5) {
//echo "Weekend: " . $date;
$shift = 8-$day_of_week;
return date('Y-m-d', strtotime("+{$shift} day", strtotime($date)));
} else {
echo "Work day ($day_of_week):" . $date . PHP_EOL;
return date('Y-m-d', strtotime('+3 day', strtotime($date)));
}
}
while ($date < $next_month) {
$date = nextWorkDay($date);
}
select user_id
from tbl
where entity_id in (24, 25)
group by user_id
having count(distinct entity_id) = 2;
create table user_balance (
user_id int,
balance decimal(9, 2) check (balance >=0)
);
create table user_balance_unsigned (
user_id int,
balance decimal(9, 2) unsigned
);
<?php
function myRound($n) {
$d = (int)log10($n) - 1;
return ceil($n/10**$d) * 10**$d;
}
<?php
$query = "SELECT COUNT(*) cnt FROM sakila.actor;";
// get DB version using PDO
$stmt = $pdo->prepare($query);
$stmt->execute();
$count = $stmt->fetchColumn();
printf("Count rows in table actor is: %d", $count);