PHP – Variables


- Advertisement -

Assigning Values to Variables
Assigning value to a variables in PHP is quite easy: use the equality(=) symbol, which also happens to be PHP’s assignment operator. This assigns the value on the right side of the equation to the variable on the left.
To use a variable in a script, simply call it by name in an expression and PHP will replace it with its value when the script is executed. Here’s an example:

In this example, the variables $name is assigned the value ‘Simon’. The echo statement is then used to print the value of this variable to the Web page.
You can also assign a variable the value of another variable, or the result of calculation.
The following example demonstrates both these situations:

Destroying Variables
To destroy a variable, pass the variable to PHP’s aptly named unset() function, as in the following example:

Inspecting Variable Content
PHP offers the var_dump() function, which accepts a variable and X-ray it for you.
Here’s example:


- Advertisement -

Leave A Reply

Your email address will not be published.