Uncategorized

Ternary PHP short-hand if/else statement

Saves using a cumbersome multi-line control structure for simple conditions like this:

// normal control structure
if (statement) {
	$variable = true;
} else {
	$variable = false;
}

// short-hand equivalent
$var = (statement) ? true : false;

// useful return statements in functions
return (statement) ? true : false;