<?php
$next = min(strtotime('next tuesday'), strtotime('next friday'));
$timer = $next - time();
$minute = 60;
$hour = $minute * 60;
$day = $hour * 24;
$days = floor($timer / $day);
$hours = floor(($timer % $day) / $hour);
$minutes = floor(($timer % $hour) / $minute);
$seconds = $timer % $minute;
var_dump($days, $hours, $minutes, $seconds);
аякс запросов нет
public function insert($table, $attrs)
{
$columns = implode(', ', array_keys($attrs));
$placeholders = implode(', ', array_fill(0, count($attrs), '?'));
$query = sprintf('INSERT INTO %s (%s) VALUES (%s)', $table, $columns, $placeholders);
return $pdo->prepare($query)->execute(array_values($attrs));
}
try {
$errors = [];
if (empty($_POST['login'])) {
$errors[] = 'Вы не ввели логин';
}
...
if (count($errors) > 0) {
throw new ValidationException($errors);
}
...
} catch (ValidationException $e) {
// Вывод ошибок
}
<?php
$a = [
1 => [
3 => [
'logo' => 'logo_3_1',
'cover' => 'cover_3_1',
],
4 => [
]
],
2 => [
5 => [
'logo' => 'logo_5_2',
'cover' => 'cover_5_2',
]
]
];
$logos = [
'logo_3_1' => 'L31',
'logo_4_1' => 'L41',
];
array_walk_recursive($a, function (&$item, $key) use ($logos) {
if (in_array($key, ['logo', 'cover'])) {
if (array_key_exists($item, $logos)) {
$item = $logos[$item];
}
}
});
echo '<pre>';
var_dump($a);
echo '</pre>';
<form action="/search" accept-charset="utf-8">
<p><input name="query" type="text"></p>
<p><button type="submit">Поиск</button></p>
</form>
<?php
if (isset($_GET['query']) && is_string($_GET['query'])) {
$stmt = $db->prepare('SELECT name FROM users WHERE name LIKE :name LIMIT 10');
$stmt->bindValue(':name', '%' . $_GET['query'] . '%');
$stmt->execute() or ...
$result = $stmt->fetchAll();
}
<?php
$path = 'path/to/img.png';
$width = $height = 300;
$background = '#ffffff';
$plain = Image::canvas($width, $height);
$plain->fill($background);
$img = Image::make($path);
$img->resize($width, null, function ($constraint) {
$constraint->aspectRatio();
});
$plain->insert($img, 'center');
$plain->save('resized.png');