<?php
class DB
{
private static $instance = null;
private $pdo;
private function __construct()
{
$host = 'localhost';
$dbname = 'your_database';
$username = 'your_username';
$password = 'your_password';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
];
$this->pdo = new PDO($dsn, $username, $password, $options);
}
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance->pdo;
}
private function __clone() {}
private function __wakeup() {}
}
class Data
{
public function __construct($param1, $param2)
{
// Получаем PDO напрямую
$this->db = DB::getInstance();
}
public function example()
{
// $query = $this->db->query("SELECT * FROM table");
// $query->execute();
// $stmt = $this->db->prepare("...");
}
}
%
как-раз намекает на добавление меток аналитики которые пригодятся при выгрузке отчётов (про это тоже есть инфа в справке) <link rel="alternate" hreflang="lang_code"... >
https://developers.google.com/search
/docs/specialty/international/managing-multi-regional-sites?hl=ru
https://developers.google.com/search
/docs/specialty/international/managing-multi-regional-sites?hl=en
https://developers.google.com/search
/docs/specialty/international/managing-multi-regional-sites
imagecolorat($img, $sx, $sy)
на imagecolorat($img, (int)$sx, (int)$sy)
- не убирало предупреждение, хотя казалось бы должно помочь.$sx = intval($sx);
$sy = intval($sy);
imagecolorat($img, $sx, $sy);
$this->keystring = '';
решается тем что свойство надо определить в классеprivate $keystring = '';
php -a
это режим интерактивного шеллаphp -f file.php
while (true) {
fwrite($f, time() . PHP_EOL);
}
time() - $end
будет меньше 1while ((time() - $end) >= 1)
$text = trim($html->find('.item.item-3 > a[rel*=category tag], 0)->plaintext);
<?php
error_reporting(-1);
ini_set('display_errors', 1);
$json_data = <<<JSON
{"messages": [
{
"id": 1,
"customer": "Dr. Kane Hill",
"customer_id": 1,
"created_at": "2024-11-19 11:18:57",
"text": "Hello, how are you?"
},
{
"id": 2,
"customer": "Dr. Kane Hill",
"customer_id": 1,
"created_at": "2024-11-19 11:20:57",
"text": "I am good, thanks! How about you?"
},
{
"id": 3,
"customer": "Prof. Samir McClure III",
"customer_id": 2,
"created_at": "2024-11-19 11:21:57",
"text": "Hey, what time is it?"
},
{
"id": 4,
"customer": "Prof. Samir McClure III",
"customer_id": 2,
"created_at": "2024-11-19 11:22:57",
"text": "It is 3 PM."
},
{
"id": 5,
"customer": "Shad Leffler",
"customer_id": 3,
"created_at": "2024-11-19 11:23:57",
"text": "Did you finish the project?"
},
{
"id": 6,
"customer": "Shad Leffler",
"customer_id": 3,
"created_at": "2024-11-19 11:24:57",
"text": "New mesh"
},
{
"id": 7,
"customer": "Prof. Samir McClure III",
"customer_id": 2,
"created_at": "2024-11-19 11:26:57",
"text": "Not bed?"
},
{
"id": 8,
"customer": "Prof. Samir McClure III",
"customer_id": 2,
"created_at": "2024-11-19 11:27:57",
"text": "Cool?"
}
]}
JSON;
$messages = json_decode($json_data, true)['messages'];
$messages2 = [];
$messageCounter = 0;
foreach($messages as $row) {
$key = $row['customer_id'];
if(!isset($messages2[$key])) {
$messages2[$key] = [
'customer' => $row['customer'],
'message_id' => (++$messageCounter),
'customer_id' => $row['customer_id'],
'messages' => [],
];
}
$messages2[$key]['messages'][] = [
'id' => $row['id'],
'created_at' => $row['created_at'],
'text' => $row['text'],
];
}
$messages2 = array_values($messages2);
echo json_encode($messages2, JSON_PRETTY_PRINT);
//TRANSLIT
или //IGNORE
₽
или ₽
. Естественно если при отображении данных делается escaping для html (html_entity_encode / htmlspecialchars) это надо будет учесть чтобы &
не превратился в &
echo json_encode(['url' => $response['confirmation']['confirmation_url']]);
exit;
window.location
<?php
class Product
{
public function __construct(
public int $id,
public ?int $parentId = null
) {
}
public function getParentId(): ?int
{
return $this->parentId;
}
}
$obj = new Product(1);
if (!empty($obj->getParentId())) {
echo 'ok';
}
public $parentId;
ошибки не будет. Всё как и написано в тексте ошибки, нельзя обратиться к типизированному свойству до его инициализации, а значит нужно либо задать значение по умолчанию при описании свойства, либо через конструктор, либо вызвав setter.<?php
$input = [
'28.06.2024' => ['Петров Петр Петрович', 'Петров Петр Петрович'],
'03.07.2024' => ['Петров Петр Петрович', 'Иванов Иван Иванович', 'Петров Петр Петрович', 'Иванов Иван Иванович'],
'02.07.2024' => ['Петров Петр Петрович', 'Иванов Иван Иванович'],
'01.07.2024' => ['Иванов Иван Иванович', 'Петров Петр Петрович', 'Иванов Иван Иванович'],
'26.06.2024' => ['Петров Петр Петрович', 'Петров Петр Петрович'],
'04.07.2024' => ['Иванов Иван Иванович']
];
$names = [];
foreach($input as $rows) {
foreach($rows as $name) {
$names[$name] = $name;
}
}
$names = array_values($names);
var_dump($names[0]);
var_dump($names[1]);
сам автор песни был в шоке от содержимого
response()
->download($pathToFile, $name, $headers)
->deleteFileAfterSend(true); //<--
Job::dispatchAfterResponse()