Variables and constants hold specific datatypes. These include:
- Boolean: Holds true or false values (1 or 0).
- Integer: Holds numbers with no decimals, such as -10, 0, 5, 10, etc.
- Double: Holds decimals numbers (Floats), such as 9.25 and 10.2528.
- String: Holds characters, such as "Car", "Toe", "7-11 Stores" and "9-11."
- Array: See Arrays.
- Object: See Objects.
- Resource: See MySQL.
- Null: Holds the value NULL.
Here's an example of variables using several datatypes: datatypes.php
|
<html> <head> <title>datatypes.php</title> </head> <body> <?php //Online Banking Balance Display
//Set the variables $yearsofservice=10; //integer $balance=115000.00; //double $message = "Welcome to Bank of Coalinga."; //string $vip=true; //boolean
//Display browser output print("<h1>".$message."</h1>"); print("Your balance is ".$balance); print("<br><br>"); print("VIP Status: ".$vip); print("<br><br>"); print($yearsofservice." year customer.");
?>
</body> </html>
|