<?php
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function encode(int $val, string $alphabet): string
{
if ($val === 0) {
return $alphabet[0];
}
$base = strlen($alphabet);
$result = '';
while ($val > 0) {
$digit = $val % $base;
$val = intdiv($val, $base);
$result = $alphabet[$digit] . $result;
}
return $result;
}
print encode(2452221399229541659, ALPHABET);
// 2V9coTtB2dB
$isNotOverlapped = $range2start > $range1end || $range1start > $range2end;
$isOverlapped = !($range2start > $range1end || $range1start > $range2end);
$isOverlapped = $range2start <= $range1end && $range1start <= $range2end;
$get = $this->get() ?? "\x00";
{
"jsonrpc": "2.0",
"id": 1,
"result": 54321
}
<VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerAdmin admin@8080
ServerName 192.168.1.1
DocumentRoot /var/www
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/8080">
DirectoryIndex 7.php
SetHandler "proxy:fcgi://127.0.0.1:8080
AddHandler php74-fcgi .php
Action php74-fcgi /cgi-bin/php74.fcgi
</Directory>
<Directory>
DirectoryIndex 8.php
SetHandler "proxy:fcgi://127.0.0.1:8082
AddHandler php82-fcgi .php
Action php82-fcgi /cgi-bin/php82.fcgi
</Directory>
ErrorLog /var/log/httpd/8080.log
CustomLog /var/log/httpd/8080.log combined
</VirtualHost>
FROM " . DB_PREFIX . "product_to_category ptc LEFT JOIN . DB_PREFIX . "category_description"
FROM oc_product_to_category ptcoc_category_description
LEFT JOIN oc_
?class API
{
public function getProduct(int $productId): Product
{
$product = $this->request(...); // Получение данных из API
return Product::from($product)
{
}
class Product
{
private int $id;
private string $title;
// прочие свойства
public function getId(): int
{
return $this->id;
}
public function getTitle(): int
{
return $this->title;
}
// прочие геттеры
// сеттеры, если нужны
public static function from(object $source): self
{
$product = new static();
$product->id = $source->id;
$product->title = $source->title;
// заполнение свойств
return $product;
}
}
...
$api = new API($login, $password);
$product = $api->getProduct(325);
$foo = ['order' => '100668327'];
echo $foo['order'];
или$foo = (object)['order' => '100668327'];
echo $foo->order;
$foo = json_decode('{"order":"100668327"}');
echo $foo->order;
или$foo = json_decode('{"order":"100668327"}', true);
echo $foo['order'];
$data = [
['id' => 1, 'field1' => 'Вася'],
['id' => 2, 'field1' => 'Петя'],
['id' => 3, 'field1' => 'Миша']
];
foreach ($data as $row) {
$stmt->execute($row);
}
или$data = [
1 => 'Вася',
2 => 'Петя',
3 => 'Миша'
];
foreach ($data as $id => $field1) {
$stmt->execute(['id' => $id, 'field1' => $field1]);
}
class A
{
private static array $instances = [];
public readonly int $value;
public function __construct(?int $value = null)
{
if ($value !== null) {
$this->value = $value;
static::$instances[] = $this;
}
}
public function summ(): int
{
return array_reduce(
static::$instances,
fn($acc, $cur) => $acc + $cur->value,
0
);
}
}
new A(2);
new A(3);
$summ = (new A())->summ();
print $summ; // 5