PHP Variables. Free online PHP and MySQL Web Database Programming Tutorial...
PHP internally uses the following data types to store variables: • Boolean
• float or double
Declaring variables in PHP
All variable names (identifiers) in PHP start with a $ sign symbol. The correct way of setting a variable in PHP is as under:
$var_name = value;
If we forget to add the $ sign at the beginning of the variable name, the code will not work. New PHP programmers often forget this, so be careful.
Consider the following PHP script:
<?php $txt = "Hello World!"; $number = 16; ?>The above code creates one string variable named $txt and one integer variable named $number. The string, like most of the languages, has to be enclosed in quotes.
Points to Remember
A constant is an identifier (name) for a simple value that cannot change during the execution of the script. By convention, constant identifiers are always uppercased. The name of a constant follows the same rules as any label in PHP, except that it does not start with the $ sign. We can define and use a PHP constant as under:
define ("FAV", "PHP"); echo FAV; // outputs PHP
Next: PHP Arithmetic