Is it possible to assign a task in a conditional expression in php?

Can you do the assignment of a conditional statement in php like this:

if(siteName_err = isValid("sitename", $_POST['sitename'], false))
{
    $siteName = $_POST['sitename'];
}
+5
source share
4 answers

Yes.

I think the most common use case is using MySQL. For example:

$result = mysql_query("SELECT username FROM user");
while ($user = mysql_fetch_assoc($result)) {
  echo $user['username'] . "\n";
}

This works because it $useris the result of an assignment. The value, regardless of what is stored in your destination, is then used as a conditional. In other words,

var_dump($i = 5);

// is equivalent to

$i = 5;
var_dump($i);

Both will print int(5), obviously.

+8
source

Yes.

, ? , , /.

PHP C, , . .

+6

Yes you can do it.

If you ask because you tried it and got a crazy error, try making a siteName_errvalid variable name by putting a dollar sign in front of it $.

+2
source

Yes, of course, and you can do the same for designs

0
source

All Articles