Author: Sun Movement
“ ===” Operator
---------------------
As we mentioned above, PHP4 added a new === operator to test whether variables have the same type. Here's an example:
--------------------------------------------- -----------------------------------------------
< ?
if (!$submit)
{
// If $submit does not exist, it implies that the form has not been submitted yet
// So the first page is displayed
?>
< html>
< head>
< style type="text/css">
td {font-family: Arial;}
< /style>
< /head>
< body>
< form method="GET" action="cookie.php">
< ; table cellspacing="5" cellpadding="5" border="0>
< tr>
< td align="center">
Please enter any value or data
< /td>
< td align="right">
< input type="text" name="yin">
< /td>
< ; /tr>
< tr>
< td align="center">
Please enter some more values or data
< /td>
< td align="right">
< input type="text" name="yang">
< /td>
< /tr>
< tr>
< tr>
< td colspan="2" align="center">
< input type="submit" name="submit" value="Test!"> ;
< /td>
< /tr>
< /table>
< /form>
< /body>
< /html>
< ?
}
else
{
// If $submit does exist, the form has been submitted
// So use the following code to process
if ($yin === $yang)
{
$result = "The two variable values and types are exactly the same";
}
else
{
$result = "The two variable values and types are completely different";
}
?>
< html>
< head>
< basefont face="Arial">
< /head>
< body>
< b>< ? echo $result; ?>< /b>
< /body>
< /html>
< ?
}
?>
-------------------------------------------------- ----------------------------------
Select syntax
--- ---------------
PHP also supports a selection syntax for the various control structures discussed so far. For example, you can do this:
--------------------------------------------- ---------------------------------------------
< ?
if ($elvis == 0)
{
echo "Elvis has left the building!";
}
else
{
echo "Elvis is still here Here!";
}
?>
Or you can do this:
< ?
if ($elvis = = 0):
echo "Elvis has left the building!";
else:
echo "Elvis is still here!";
endif;
?>
---------------------------------------------------------------- -------------------------------
The second option is exactly the same as the first one, here This structure simply replaces the first brace with a colon [:], removes the second brace, and ends with an "endif" statement.
These are the contents of the second part. Next time, we'll bring you loops, arrays, and more forms - so don't miss it!