PHP ideal way to check function returns true
Actually, both methods assign the value first before comparing its value. Therefore, in terms of efficiency, there's no difference.

For code readability, you could write extra parentheses around the assignment if you choose method A. Method B has a slight advantage when you have to perform debugging before the branch, i.e.:

$res = $db-&gt;getResult(95);
var_dump($res); // added for debugging without having to move the code out of the condition
echo $res ? $res : 'fail';


The ternary operator I've used above is yet another way to do your branching; its efficiency is in the same ballpark though. Since the variable itself is used solely in the truthy branch you can also use the shortened ternary operator (>= 5.3) like so:

echo $res ?: 'fail';


Although ternary operators are a powerful concept, they're easy to abuse as well and can cause either bugs or a WTF during code review. My personal guideline is to start favouring an if/else construct when either the condition has multiple sub-expressions or when the manual is opened under operator precedence.