Q:

PHP: return a part of an if () { }

Let's say I have this code:
if (md5($_POST[$foo['bar']]) == $somemd5) {
  doSomethingWith(md5($_POST[$foo['bar']]);
}

I could shorten that down by doing:
$value = md5($_POST[$foo['bar']];
if ($value == $somemd5) {
  doSomethingWith($value);
}

But is there any pre-set variable that contains the first or second condition of the current if? Like for instance:
if (md5($_POST[$foo['bar']]) == $somemd5) {
  doSomethingWith($if1);
}

May be a unnecessary way of doing it, but I'm just wondering.

A:

No, but since the assignment itself is an expression, you can use the assignment as the conditional expression for the if statement.

if (($value = md5(..)) == $somemd5) { ... }

In general, though, you'll want to avoid embedding assignments into conditional expressions:

The code is denser and therefore harder to read, with more nested parentheses.
Mixing = and == in the same expression is just asking for them to get mixed up.

