T
T
Theory Theory2020-05-25 17:51:29
PHP
Theory Theory, 2020-05-25 17:51:29

How does the terra operator work in PHP?

$a = "";
$b = 5;

$c = $a ?? $b;    // $c примет значение $a, если она существует и не равна null

// $a существует и равна пустой строке. А пустая строка равна null. То есть $c должна принять значение $b
echo "" == null;  // true

// но в итоге получаем $c == "";
echo $c == ""; 	  // true

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-05-25
@Narbek

echo "" == null; // true
Using ?? the condition is checked, that is, the strict equality of the first argument to null, and not just an empty value
echo "" === null; // false

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question