SoFunction
Updated on 2025-04-09

PHP4 practical application experience (9)

Author: Sun Sports

" ===" operator
------------------------

As we have mentioned above, PHP4 has added a new === operator to test whether variables have the same type. Here is an example:


--------------------------------------------------------------------------------
< ?

if (!$submit)
{
// If $submit does not exist, this implies that the form has not been submitted yet
// So display the first page

?>

< html>
< head>
< style type="text/css">
td {font-family: Arial;}
< /style>
< /head>

< body>

< form method="GET" action="">
< 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 values ​​and types of the two variables are exactly the same";
}
else
{
$result = "The values ​​and types of the two variables are completely different";
}

?>

< html>
< head>
< basefont face="Arial">
< /head>

< body>
< b>< ? echo $result; ?>< /b>

< /body>
< /html>

< ?
}
?>
--------------------------------------------------------------------------------


Select syntax
------------------

PHP also supports a selective syntax for the various control structures currently discussed. For example, you could do this:

--------------------------------------------------------------------------------
< ?

if ($elvis == 0)
    {
echo "Elvis has left the building!";
    }
else
    {
echo "Elvis is still 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. In this structure, simply replace the first brace with a colon [:], remove the second brace, and end with the "endif" statement.

These are the contents of the second part. Next time, we will bring you loops, arrays and more forms - so don't miss it!