A
A
Apxu2018-03-03 16:46:26
PHP
Apxu, 2018-03-03 16:46:26

Who can clearly explain why the code is executed this way?

Can you please tell me why PHP enters the if condition?

$test = floatval(0);
if ($test == 'wrong_promo') {
    echo 'По идее мне сюда нельзя заходить, но я зайду посмотрю!';
}else{
    echo "Жду...";
}

PHP link online sandbox.onlinephpfunctions.com/code/f7befef33390ce...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artyom Belousov, 2018-03-03
@Apxu

It's all about type conversion. 'wrong_promo' is converted to a float, but since the beginning of this string does not contain a number, it is converted to 0, that is, it becomes equal to $test

E
Ernest Faizullin, 2018-03-03
@erniesto77

strongly-typed comparison to help
if ($test === 'wrong_promo') { ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question