PHP Programing language

adplus-dvertising
How can Using Optional Parameter
Previous Home Next
<html>
<head>
<title>Using Optional Parameter</title>
</head>
<body>
<h1>Using Optional Parameter</h1>
<?php
$a = array('A', 'B', 'C', 'D', 'E');
$admin = array('F', 'G');

function check_access($username, $adminonly = false) 
{
    global $a, $admin;

    if (in_array($username, $admin)) 
	{
        return true;
    }

    if (!($adminonly) && in_array($username, $a)) 
	{
        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>";
?>  
</body>
</html>

Output:

Previous Home Next