Using Optional Parameters
<?php
$access = array('a', 'c', 'h', 'r', 'r');
$admin = array('e', 'q');
function check_access($username, $adminonly = false) {
global $access, $admin;
if (in_array($username, $admin)) {
return true;
}
if (!($adminonly) && in_array($username, $access)) {
return true;
}
return false;
}
echo check_access('r') ? 'is' : 'is NOT' ," allowed.</p>";
echo check_access('q') ? 'is' : 'is NOT' ," allowed.</p>";
echo check_access('r', true) ? 'is' : 'is NOT' ," an admin.</p>";
echo check_access('q', true) ? 'is' : 'is NOT' ," an admin.</p>";
?>
Related examples in the same category