コード例 #1
0
</head>
<body>
<!-- Let's create a new array called $users that have the following keys and values

$users['first_name'] = "Michael";
$users['last_name'] = "Choi";

Create a function where you can pass this $users and which would print an output that looks like below

There are 2 keys in this array: first_name, last_name
The value in the key 'first_name' is 'Michael'.
The value in the key 'last_name' is 'Choi'. -->


<?php 
function print_users($arr)
{
    echo 'There are ' . count($arr) . ' keys in this array: ';
    foreach ($arr as $key => $value) {
        echo "'" . $key . "' ";
    }
    echo '<br>';
    foreach ($arr as $key => $value) {
        echo "The value in the key '" . $key . "' is '" . $value . "'." . '<br>';
    }
}
$users = array('first_name' => 'Michael', 'last_name' => 'Choi');
print_users($users);
?>
</body>
<html>
    }
    $num_emp = 0;
    echo "<form action=\"delete_employees.php\" method=\"post\" align=\"center\">" . "\n";
    echo "<h1 style=\"text-align:center\"> Managers </h1>" . "\n";
    $num_emp += print_employee("MANAGER");
    echo "<h1 style=\"text-align:center\"> Cooks </h1>" . "\n";
    $num_emp += print_employee("COOK");
    echo "<h1 style=\"text-align:center\"> Cashiers </h1>" . "\n";
    $num_emp += print_employee("CASHIER");
    echo "<h1 style=\"text-align:center\"> Waiters </h1>" . "\n";
    $num_emp += print_employee("WAITER");
    echo "<h1 style=\"text-align:center\"> Delivery Boys </h1>" . "\n";
    $num_emp += print_employee("DELIVERY_BOY");
    if (!$num_emp) {
        echo "<script type=\"text/javascript\">" . "\n";
        echo "alert(\"No Employees Added!!!\");" . "\n";
        echo "</script>" . "\n";
        echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=admin.html\">";
        return;
    }
    echo "<input type=\"submit\" value=\"Delete Selected Employees\">" . "\n";
}
?>
<body background="1.png">
<?php 
print_users();
?>
</form>
</body>
</html>
コード例 #3
0
ファイル: intro10.php プロジェクト: kayeaborot/Codes
<?php

$users['first_name'] = "Michael";
$users['last_name'] = "Choi";
$keyname = [];
function print_users($users, $keyname)
{
    foreach (array_keys($users) as $key) {
        $keyname[] = $key;
    }
    echo "There are " . count($users) . " keys in this array: " . $keyname[0] . ", " . $keyname[1] . ".<br>";
    echo "The value in the key '" . $keyname[0] . "' is '" . $users['first_name'] . "'.<br>";
    echo "The value in the key '" . $keyname[1] . "' is '" . $users['last_name'] . "'.<br>";
}
echo print_users($users, $keyname);
?>