echo explode('/', $url,2)[1];
<?php
$data = [
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2, 'c' => 3]
];
$query="INSERT INTO t (a, b, c) VALUES " . implode(
', ',
array_fill(
0,
count($data),
'(' . implode (', ', array_fill(0, count($data[0]), '?')) . ')'
)
);
echo $query;
$values = array_reduce(
$data,
function($ac, $el) {
return array_merge($ac, array_values($el));
},
[]
);
var_export($values);
$q=$pdo->prepare($query);
$q->execute($values);
<?php
$phone = '1234567';
$sql = "INSERT INTO sportusers (userdate, phone)
SELECT NOW(), :userphone
WHERE NOT EXISTS (
SELECT 1 FROM sportusers s2
WHERE s2.phone = :userphone
AND userdate > date_sub(now(), interval 12 HOUR)
)";
$stmt = $pdo->prepare($sql);
$res = $stmt->execute([':userphone' => $phone]);
if($stmt->rowCount() > 0 ){
echo "Запись сделана";
} else {
echo "Try later";
}
if (in_array($person, $arr['Ученик'])) {
echo "$person is Ученик";
} elseif (in_array($person, $arr['Учитель'])) {
echo "$person is Учитель";
}
foreach ($arr as $position => $names) {
if (in_array($person, $names)) {
echo "$person is $position";
}
}
<?php
$art = '(#КЛП1483П1)';
echo trim($art, ')(#');
echo PHP_EOL;
preg_match('/^\(#(.+)\)$/', $art, $m);
echo $m[1];
echo PHP_EOL;
echo substr($art, 2, -1);
echo PHP_EOL;
$sql = "INSERT INTO `users` (`phone`,`name`,`fio`,`user_email`,`user_password`,`activity`,`twath`,`actvml`,`vmlstr`,`code`,`group`,`city`,`DateReg`,`LastEnter`,`user_ip`,`user_login`,`skin`,`sex`,`money`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $mysqli->prepare($sql);
$params = [$phone, $name, '-', $mail, $pasw, 1, 0, 0, 1, $code, 1, $city, $dreg, $dreg, $ip, $login, 0, $sex, 0];
$stmt->bind_param("ssssssssssssssssssi", ...$params);
$res = $stmt->execute();
<?php
$from = DateTime::createFromFormat("m.Y", "1.2023");
$to = DateTimeImmutable::createFromFormat("m.Y", "12.2024");
$interval = DateInterval::createFromDateString('1 month');
while ($from < $to) {
echo $from->format('m.Y') . PHP_EOL;
$from = $from->add($interval);
}
echo $to->format('m.Y') . PHP_EOL;
<?php
$response = '{"status":"success","1":{"transaction":"8025400","email":"Не указана","amount":"21.38","currency":"RUB","currency_amount":"20.00","comission_percent":"6.90","comission_fixed":"0.00","amount_profit":"20.00","method":"Не выбран","payment_id":"1618399991","description":"Покупка доступа на 2 дня","date":"2023-03-13 19:40:46","pay_date":"2023-03-13 19:40:46","transaction_status":"0","custom_fields":"null","webhook_status":"0","webhook_amount":"0"}}';
$data = json_decode($response, true);
$transaction_status = $data["1"]["transaction_status"] ?? -1;
switch ($transaction_status) {
case -1:
echo 'Статус транзакции неизвестен';
exit(0);
case 0:
echo 'Статус транзакции = 0';
exit(0);
default:
echo 'Статус транзакции не равен 0';
}
Argument #2 ($array) must be of type ?array, string given in
Аргумент #2 ($array) должен иметь тип ?array, строка указана в
echo implode(',', array_column($arr['domains'], 'fqdn'));
<?php
$html =" <span>
123 </span>";
echo json_encode(["content"=>$html]);
$html =" <span>
123 </span>";
echo '{"content":'.json_encode ($html) .'}';
usort($arr, fn($a, $b)=>$b['STATUS_WORK_DAY']<=>$a['STATUS_WORK_DAY']);
<?php
function getTags($strTag) {
return array_combine(
array_map(
fn($attribute) => array_shift(explode("=", $attribute)),
explode(" ", trim($strTag))
),
explode(" ", trim($strTag))
);
}
function getAttributes($strTag) {
return array_map(
fn($attribute) => array_pop(explode("=", $attribute)),
getTags($strTag)
);
}
preg_match_all('/(?<=\<img).*?(?=>)/', $this->html, $match, PREG_PATTERN_ORDER);
$this->tags = array_map(
fn($strTag) => [
"original" => "<img " . $strTag . ">",
"attributes" => getAttributes($strTag)
],
$match[0]
);
<?php
$input = 'value.id.price.data.get.value';
$result = [];
$r = &$result;
foreach(explode('.', $input) as $k) {
$r[$k] = [];
$r = &$r[$k];
}
print_r($result);
//Выбираем все категории с базы данных
$stmt = $pdo->prepare("SELECT * FROM category WHERE id=:id OR name=:name");
$stmt->execute(['id'=> $id, 'name'=> $name]);
$res = $stmt->fetchAll(PDO::FETCH_ASSOC);
//Выводим категории по колонке имени в базе
foreach ($res as $row) {
echo '<a href="/"><b>' . $row['id'] . '</b></a><br>' . PHP_EOL;
}