public static function get($id)
{
$user_bank = self::findOneBy('`user_id` = ?', [$id]);
if (!$user_bank) {
$user_bank = new self();
$user_bank->user_id = $id;
$user_bank->deposit = 0;
$user_bank->deposit_sum = 0;
$user_bank->percent = 10;
$user_bank->exchange_sum = 0;
$user_bank->save();
}
return $user_bank;
}
echo function()[1];
echo function()[1]->hello;
<?php
# Author - Fedor Vlasenko, vlasenkofedor@gmail.com
define('METHOD', $_SERVER['REQUEST_METHOD']);
define('URI', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
function router($url, ...$args)
{
(empty($args[1]) || false !== strpos(METHOD, $args[0]))
&& (URI === $url || preg_match('#^' . $url . '$#iu', URI, $match))
&& die(call_user_func_array(end($args), $match ?? []));
}
router('/api/games', 'GET', function () {
echo 'список игрушек';
});
router('/api/game/(\d+)', 'GET', function (...$args) {
echo 'информация о игрушке: ', $args[1];
});
router('/api/games', 'POST', function () {
echo 'добавить новую игрушку';
});
router('/api/games/(\d+)', 'PUT', function (...$args) {
echo 'обновить существующую игрушку: ', $args[1];
});
router('/api/games/(\d+)', 'DELETE', function (...$args) {
echo ' удалить игрушку: ', $args[1];
});
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
echo '404';
<?php
$generator = (function (): \Generator {
yield 1;
yield 2;
})()
var_dump($generator->current());
$generator->next();
var_dump($generator->current());
select `id` from `table` where (SELECT @s:= @s + `size` from (SELECT @s:= 0) s) < 1000000 order by `id` desc ;
select @sum := 0;
select count(*)
from (select @sum := @sum + size sum_size
from `table`
) a
where sum_size < 1000000;
SELECT COUNT(*) FROM `table` as t WHERE (SELECT SUM(size) FROM `table` WHERE `id` >= t.id ORDER BY id DESC) <= 1000000 ORDER BY id DESC
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('//img[contains(@class, "popup-img")]');
foreach($nodes as $node) {
$a = $dom->createElement('a');
$a->setAttribute('class', $node->getAttribute("class"));
$a->setAttribute('title', $node->getAttribute("alt"));
$href = parse_url($node->getAttribute("src"), PHP_URL_PATH);
$a->setAttribute('href', '..' . str_replace('/thumbs/100/', '/', $href));
$a->setAttribute('style', "background: url('..$href'); -webkit-background-size:cover; background-size:cover;");
$node->parentNode->insertBefore($a, $node);
$node->parentNode->removeChild($node);
}
echo $dom->saveHTML();