PHP Variables |
Syntax of assigning variable in PHP:
$varName = value;
or,
$varName1 = "Value";
How we can understand the variable types in PHP?
It is very easy to understand the variable types in PHP. The value in double inverted comma as a string value either you write any numerical value into double inverted comma. Always remember to put double inverted comma around the variables if you write any alphabet character, words or sentences.
If you assign any value to the variable as integer or numeric value without double inverted comma then you can say that it is an integer value like $x = 5; This is Integer Variable in PHP.
If you assign any decimal value to an variable when it is known as float variable like $x = 3.4;
Rules of variable in PHP:
- The name of the variable start with dollar sign ($)
- The variable name must be start with underscore (_) or letter
- The variable name is not start with number
- A variable name cannot contain any a special character like &, #, @ etc.
- A variable name only contains alphanumeric character and underscore (_)
Note: Variable names are case sensitive that means $age and $AGE are two different variables.
To print the the output of the variable we can use echo or print statement. For example:
Example 1:
<?php
$var = "Hello Learner!!!" // String Variable
echo $var;
?>
Output:
Hello Learner!!!
Example 2:
<?php
$var = 1 // Integer Variable
echo $var;
?>
Output:
1
Example 2:
<?php
$var = 1.2 // Float Variable
echo $var;
?>
Output:
1.2
PHP Syntax with examples
---
PHP Syntax with examples || PHP Tutorial 2 |
No comments:
Post a Comment