Combine if-query with allocation


Combine if-query with allocation

是否有可能将分配组合到if-查询中,应该这样做吗?

$textxPos = $xPos + $fieldData["coordinates"]["x"] / $divisor;
if ($textxPos < 0) {
  ..
}

一样:

if ($link['value'] = trim($link['value'])) {
  ..
}

Try this:

if(($textxPos = $xPos + $fieldData["coordinates"]["x"] / $divisor) && $textxPos<0 )
{
    echo "true";
}
else
{   
    echo "false";
}

例子:

<?php
$var1 = "112";
$var2 = "112";
$divisor = "10";
if(($textxPos = $var1 + $var2 / $divisor) && $textxPos<0 )
{
    echo "true";
}
else
{   
    echo "false"; //$textxPos=123.2
}
?>

首先赋值给$textxPos,然后用&&运算符检查条件。