doflamingo doflamingo - 13 days ago 5x
PHP Question

PHP - What is this if statement meaning?

I use PHP around 3 months see many syntax.

but cannot understand what is this mean.

if($foo = 'somevalue') //or if($foo = $somevalue)


I see only if($foo) this mean if($foo == TRUE). or if($foo ==,>,< somevalue)

but in this case, if$foo hold some value???


You are just simultaneously assigning a value to $foo and evaluating it in the if statement. So if the value of $foo corresponds to false, then code inside the if statement would not execute. As an example:

if ($foo = 12) { // foo's value is now 12
    // code here would execute
echo $foo; // 12

if ($foo = 0) { // foo's value is now 0
    // would not execute
echo $foo; // 0