One day i was assigned to update a website which created by my mentor in php, while updating the some parts of the function I've found a 1 line of which I've never encountered before in my PHP life, so i asked him if what is the purpose of this line of code then he said it is a shortcut If statement in php, i placed the sample line of codes below, please check.
$authenticated = true;// 1 standard if-else statementif ($authenticated){echo 'YES';
}else{echo 'NO';
}// same with 1if ($authenticated) { echo 'YES'; } else { echo 'NO'; }// [2] lil bit shortcutif ($authenticated)echo 'YES';
elseecho 'NO';
// 3 the shortcutecho $result = ($authenticated) ? 'YES' : 'NO';
No comments:
Post a Comment