$login = $_POST['login'];
$hash = password_hash($_POST['password']);
$login = $_POST['login'];
$password = $_POST['password']; // не хешируем
SELECT * FROM users WHERE login = '$login'
if (password_verify($password, $hash_from_db)) {
// пользователь аутентифицирован
} else {
// пара логин/пароль неверная
}
class Calc {
private $number = 0;
public function __construct($n){
$this->number = $n;
}
public function plus($n){
$this->number += $n;
return $this;
}
public function minus($n){
$this->number -= $n;
return $this;
}
public function result(){
return $this->number;
}
}
echo (new Calc(100))->plus(50)->minus(75)->result(); // 75
Как избегать foreach внутри foreach?
Очень часто вижу на разных форумах, в коммах в вк и тд юзать цикл внутри цикла не правильно
Каким образом можно сделать это по другому(правильно) ?
create table `calendar` (
`event` varchar(64),
`year` smallint unsigned,
`month` tinyint unsigned,
`day` tinyint unsigned,
`hour` tinyint unsigned,
`minute` tinyint unsigned
);
insert into calendar values
('December 31 every year at 23:55', null, 12, 31, 23, 55),
('every minute in december 2020', 2020, 12, null, null, null),
('every hour at first of month', null, null, 1, null, 0)
;
select `event`
from `calendar`
where
(`year` is null or `year` = year(now())) and
(`month` is null or `month` = month(now())) and
(`day` is null or `day` = day(now())) and
(`hour` is null or `hour` = hour(now())) and
(`minute` is null or `minute` = day(now()))
;
$x="foobar http://example.com foobar s;fskdljslkjsdklf www.google.com";
$x = preg_replace("~(https?://(?:www\.)?[^\s]+)~i","<a href='$1'>$1</a>", $x);
$x = preg_replace("~(www.([^\s]+))~i", "<a href='http://$1'>$1</a>", $x);
echo $x;