$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
$json = file_get_contents('php://input');
$data = json_decode($json);
WITH
`slots` (`slot`) AS (
WITH RECURSIVE
`dates` (`date`, `add`) AS (
SELECT CURDATE(), 1
UNION SELECT `date` + INTERVAL 1 DAY, `add` + 1
FROM `dates`
WHERE `add` < 365
),
`hours` (`hour`, `idx`) AS (
WITH
`c` (`count`) AS (
SELECT LENGTH('02:00,05:00,07:00,08:00') - LENGTH(REPLACE('02:00,05:00,07:00,08:00', ',', '')) + 1
)
SELECT SUBSTRING_INDEX('02:00,05:00,07:00,08:00', ',', 1), 1
UNION SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('02:00,05:00,07:00,08:00', ',', `idx` + 1), ',', -1), `idx` + 1 AS `idx`
FROM `hours`
JOIN `c`
WHERE `idx` < `c`.`count`
)
SELECT CAST(CONCAT(`date`, ' ', `hour`) AS DATETIME) AS `slot`
FROM `dates`
JOIN `hours`
HAVING `slot` > CURTIME()
)
SELECT `s`.`slot`
FROM `slots` AS `s`
LEFT JOIN `autoposting_planned` AS `ap`
ON `ap`.`datetime` = `s`.`slot`
WHERE `ap`.`datetime` IS NULL
ORDER BY `s`.`slot`
LIMIT 1
- SPL:
. Calling get_object_vars() on an ArrayObject instance will now always return
the properties of the ArrayObject itself (or a subclass). Previously it
returned the values of the wrapped array/object unless the STD_PROP_LIST
flag was specified.