$args = [
'name1' => FILTER_SANITIZE_STRING,
'age1' => FILTER_SANITIZE_NUMBER_INT,
'weight1' => FILTER_SANITIZE_NUMBER_FLOAT,
];
$defaults = [
"name1" => "по умолчанию",
"age1" => "по умолчанию",
"weight1" => "по умолчанию",
];
$results = array_merge($defaults, filter_input_array(INPUT_GET, $args));
// вывод
foreach ($results as $name => $value) {
printf('<p>%s: %s</p>', $name, $value);
}
$options = [
[null, $_LNG['TYPE_ORDER']],
['select_all', $_LNG['ALL_TYPES']],
['select_domain', $_LNG['DOMAIN']],
['select_server', $_LNG['SERVER']],
['select_ssl', $_LNG['SSL']],
['select_desing', $_LNG['DESING']],
['select_script', $_LNG['SCRIPT']],
['select_layout', $_LNG['LAYOUT']],
['select_adv', $_LNG['ADV']],
['select_seo', $_LNG['SEO']],
];
printf('const options = %s;', json_encode($options));
options
полноценный элемент select
со всеми опциями: createSelect = () => {
const select = document.createElement('select');
options.forEach(([value, title]) => {
const option = document.createElement('option');
option.innerText = title;
if (value) {
option.value = value;
} else {
option.setAttribute('disabled', true);
option.setAttribute('selected', true);
}
select.appendChild(option);
});
return select;
};
0.25
как ни округляй, будет 0
для $amount < 2
$rand = mt_rand(1, 1000);
$bad = '...';
if ($rand < 150) {
$k = 1;
$message = '$ (x0) ❌';
} elseif ($rand < 300) {
$k = 0.75;
$message = "$ (x0.25) $bad";
} elseif ($rand < 450) {
$k = 0.5;
$message = "$ (x0.5) $bad";
} elseif ($rand < 600) {
$k = 0.25;
$message = "$ (x0.75) $bad";
}
$delta = round($amount * k);
$res = $user->balance - $delta;
$restxt = 'Вы проиграли ' . number_format($delta, 0, '', '.') . $message;
$delta = $amount === 1 ? max(1, floor($amount * k)) : floor($amount * $k);
но следующий вопрос будет «а вот 2 при $k === 0.25
тоже округляется до 0» $start = new DateTimeImmutable('1878-10-11');
$finish = new DateTimeImmutable('2009-10-13');
$interval = $start->diff($finish);
$daysDiff = $interval->format('%a');
$randomDays = rand(0, $daysDiff);
$randomDate = $start->add(new DateInterval("P${randomDays}D"));
echo $randomDate->format('Y-m-d'); // 1896-06-24
.htaccess
в конфиг NGINX. С помощью Google, SO и Habr.QnA )/index.php
, а там уже логика внутри PHP узнавала запрошенный URL /section1/page2
и отдавала соответствующий ответ. Такие решения универсальны относительно веб-сервера..htaccess
иногда кладут в проект, потому, что это легкий невидимый файл, который не помешает. Но поможет понять ожидаемое поведение веб-сервера. Конфиги NGINX лежат отдельно от проекта, поэтому их не прилагают. Хотя иногда приводят пример в документации. .
начало
---|---|---
к | 1
о -
н | 2 1
е -
ц | 3 2 1
if - else if - else
function ranges(int $a, int $b): array
{
$start = 20;
$finish = 30;
$result = [
'before' => null,
'match' => null,
'after' => null,
];
if ($a < $start) {
if ($b < $start) {
$result['before'] = [$a, $b];
} else {
$result['before'] = [$a, $start];
if ($b < $finish) {
$result['match'] = [$start, $b];
} else {
$result['match'] = [$start, $finish];
$result['after'] = [$finish, $b];
}
}
} else if ($a < $finish) {
if ($b < $finish) {
$result['match'] = [$a, $b];
} else {
$result['match'] = [$a, $finish];
$result['after'] = [$finish, $b];
}
} else {
$result['after'] = [$a, $b];
}
return $result;
}
print(json_encode(ranges(5, 25))); // {"before":[5,20],"match":[20,25],"after":null}
$arr = [$start, $finish, $a, $b];
sort($arr, SORT_NUMERIC);
1, 2, 3, 2, 3, 2, 1
0 + + - + - -
^ ^ ^ в этих точках знак поменялся
Складывать найденные точки в два массива: максимумы и минимумы.$str = "attachment=12345";
list($number) = sscanf($str, "attachment=%d");
echo $number; // 12345
rgb(0, 0, 0)
соответствует множество hsl(*, *, 0)
.