I am wanting to see if there is a simplified way of doing an if
statement that is checking multiple conditions, where it uses data from the same function.
if($class->function($id) && $class->function($id)['key'] > 0)
{
//Do something...
}
The issue here is we're making 2 database calls that retrieve the same data. One obvious solution is doing the following:
$classVariable = $class->function($id);
if($classVariable && $classVariable['key'] > 0)
{
//Do something...
}
My question specifically is, can I achieve the same effect all inside the if
statement? For example(this will not work):
if($classVariable = $class->function($id) && $classVariable['key'] > 0
{
//Do something...
}
Is this possible, and is there a preferred way of doing this? It seems to me that defining and using it in the same statement would be cleaner code...