<a href="geo:37.786971,-122.399677;u=35">Wikimedia Headquarters</a>
function arrayCompressor($data, $key = null, &$result = []): array
{
if (is_array($data)) {
foreach ($data as $index => $param) {
if ($key === null) {
$newKey = $index;
} else {
$newKey = $key . '[' . $index . ']';
}
arrayCompressor($param, $newKey, $result);
}
} else {
$result[$key] = $data;
}
return $result;
}
$array = [
'RoadServiceAutos' => [
[
'RoadServices' => [
[
'CountryAlpha2Code' => 'RU',
'CountryBeta2Code' => 'EN',
],
],
'Test' => "test",
],
],
];
print_r(arrayCompressor($array));
<?php
enum CurrenciesEnum: string
{
case RUB = 'RUB';
case USD = 'USD';
case EUR = 'EUR';
case GBP = 'GBP';
case JPY = 'JPY';
case CNY = 'CNY';
private const DATA = [
'RUB' => ['name' => 'Рублей', 'short' => '₽', 'ratio' => 1, 'default' => 1, 'display' => 1],
'USD' => ['name' => 'Dollar', 'short' => '$', 'ratio' => 1, 'default' => 1, 'display' => 1],
'EUR' => ['name' => 'Euro', 'short' => '€', 'ratio' => 1, 'default' => 1, 'display' => 1],
'GBP' => ['name' => 'Pound', 'short' => '£', 'ratio' => 1, 'default' => 1, 'display' => 1],
'JPY' => ['name' => '円', 'short' => '¥', 'ratio' => 1, 'default' => 1, 'display' => 1],
'CNY' => ['name' => '元', 'short' => 'Ұ', 'ratio' => 1, 'default' => 1, 'display' => 1],
];
public function code(): string
{
return $this->value;
}
public function name(): string
{
$this->insureValue();
return self::DATA[$this->value]['name'];
}
public function short(): string
{
$this->insureValue();
return self::DATA[$this->value]['short'];
}
public function ratio(): string
{
$this->insureValue();
return self::DATA[$this->value]['ratio'];
}
public function default(): string
{
$this->insureValue();
return self::DATA[$this->value]['default'];
}
public function display(): string
{
$this->insureValue();
return self::DATA[$this->value]['display'];
}
private function insureValue(): void
{
if (!isset(self::DATA[$this->value])) {
throw new InvalidArgumentException($this->value);
}
}
}
echo CurrenciesEnum::RUB->code(), PHP_EOL;
echo CurrenciesEnum::RUB->name(), PHP_EOL;
echo CurrenciesEnum::RUB->short(), PHP_EOL;
<?php
enum CurrenciesEnum
{
case RUB;
case USD;
case EUR;
case GBP;
case JPY;
case CNY;
public function code(): string
{
return $this->name;
}
public function name(): string
{
return self::getField($this->name, 'name');
}
public function short(): string
{
return self::getField($this->name, 'short');
}
public function ratio(): string
{
return self::getField($this->name, 'ratio');
}
public function default(): string
{
return self::getField($this->name, 'default');
}
public function display(): string
{
return self::getField($this->name, 'display');
}
private static function getField(string $currency, string $field): string
{
$data = [
self::RUB->name => ['name' => 'Рублей', 'short' => '₽', 'ratio' => 1, 'default' => 1, 'display' => 1],
self::USD->name => ['name' => 'Dollar', 'short' => '$', 'ratio' => 1, 'default' => 1, 'display' => 1],
self::EUR->name => ['name' => 'Euro', 'short' => '€', 'ratio' => 1, 'default' => 1, 'display' => 1],
self::GBP->name => ['name' => 'Pound', 'short' => '£', 'ratio' => 1, 'default' => 1, 'display' => 1],
self::JPY->name => ['name' => '円', 'short' => '¥', 'ratio' => 1, 'default' => 1, 'display' => 1],
self::CNY->name => ['name' => '元', 'short' => 'Ұ', 'ratio' => 1, 'default' => 1, 'display' => 1],
];
if (!isset($data[$currency])) {
throw new InvalidArgumentException($currency);
}
return $data[$currency][$field];
}
}
echo CurrenciesEnum::RUB->code(), PHP_EOL;
echo CurrenciesEnum::RUB->name(), PHP_EOL;
echo CurrenciesEnum::RUB->short(), PHP_EOL;
final class Currency
{
public function __construct(
readonly string $code,
readonly string $name,
readonly string $short,
readonly int $ratio = 1,
readonly int $default = 1,
readonly int $display = 1,
)
{
}
}
final class CurrenciesStorage
{
private static self|null $instance = null;
/** @var Currency[] */
private array $currencies = [];
private function __construct()
{
}
public static function getInstance(): self
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function add(Currency $currency): void
{
$this->currencies[$currency->code] = $currency;
}
public function has(string $code): bool
{
return isset($this->currencies[$code]);
}
public function get(string $code): Currency|null
{
return $this->currencies[$code] ?? null;
}
public function all(): array
{
return $this->currencies;
}
}
$storage = CurrenciesStorage::getInstance();
$storage->add(new Currency('RUB', 'Рублей', '₽'));
$storage->add(new Currency('USD', 'Dollar', '$'));
$storage->add(new Currency('EUR', 'Euro', '€'));
// Получить данные по одному объекту
echo $storage->get('RUB')->code, PHP_EOL;
echo $storage->get('RUB')->name, PHP_EOL;
echo $storage->get('RUB')->short, PHP_EOL;
// Получить все объекты
var_dump($storage->all());
Определяет имя файла, который будет автоматически обрабатываться перед основным файлом. Файл вызывается так, будто он был подключён при помощи функции require, так что include_path также используется.
Определяет имя файла, который будет автоматически обрабатываться после основного файла. Файл вызывается так, будто он был подключён при помощи функции require, так что include_path тоже используется.
function converter(array $input): array
{
$output = [];
foreach ($input as $items) {
foreach ($items as $key => $value) {
if (!isset($output[$key])) {
$output[$key] = [];
}
$output[$key][] = $value;
}
}
return array_values($output);
}
$input = [
[34 => 'uni-1-34'],
[34 => 'uni-2-34'],
[44 => 'uni-1-44'],
[44 => 'uni-2-44'],
];
print_r(converter($input));
composer dump-autoload
$imagejpeg = imagecreatefromjpeg(__DIR__ . '/test.jpg');
$imagejpeg = imagecropauto($imagejpeg, IMG_CROP_THRESHOLD, 1, 16777215);
header('Content-Type: image/jpeg');
echo imagejpeg($imagejpeg);
<?php
$str = <<<EOT
<a aria-label="фотография" onclick="return showPhoto('-100714248_457263530', 'wall-100714248_195733', {"temp":{"x":"https:\/\/sun1.tattelecom-nbc.userapi.com\/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew\/BLrYmamsJYw.jpg","y":"https:\/\/sun1.tattelecom-nbc.userapi.com\/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag\/ReADACWxqrc.jpg","z":"https:\/\/sun2.tattelecom-nbc.userapi.com\/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg\/Q-ytzLXop9M.jpg","x_":["https:\/\/sun1.tattelecom-nbc.userapi.com\/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew\/BLrYmamsJYw",359,604],"y_":["https:\/\/sun1.tattelecom-nbc.userapi.com\/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag\/ReADACWxqrc",480,807],"z_":["https:\/\/sun2.tattelecom-nbc.userapi.com\/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg\/Q-ytzLXop9M",587,987],"base":""},"queue":1}, event)" style="width: 68px; height: 115px;background-image: url(https://sun1.tattelecom-nbc.userapi.com/GPHn0KGJ-tYVSZgVyGegulTCONVIiCM4J_8_QQ/TLNR1gH5bAE.jpg);" class="page_post_thumb_wrap image_cover page_post_thumb_last_column fl_l page_post_thumb_not_single" data-photo-id="-100714248_457263530"></a>
EOT;
if (preg_match('/return showPhoto\(.+, {(.+)}, .+\)/', $str, $output)) {
$linkData = json_decode('{' . $output[1] . '}', true);
print_r($linkData);
}
Array
(
[temp] => Array
(
[x] => https://sun1.tattelecom-nbc.userapi.com/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew/BLrYmamsJYw.jpg
[y] => https://sun1.tattelecom-nbc.userapi.com/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag/ReADACWxqrc.jpg
[z] => https://sun2.tattelecom-nbc.userapi.com/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg/Q-ytzLXop9M.jpg
[x_] => Array
(
[0] => https://sun1.tattelecom-nbc.userapi.com/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew/BLrYmamsJYw
[1] => 359
[2] => 604
)
[y_] => Array
(
[0] => https://sun1.tattelecom-nbc.userapi.com/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag/ReADACWxqrc
[1] => 480
[2] => 807
)
[z_] => Array
(
[0] => https://sun2.tattelecom-nbc.userapi.com/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg/Q-ytzLXop9M
[1] => 587
[2] => 987
)
[base] =>
)
[queue] => 1
)