What is variable?
A variable is a representation of a value. Let's take for instance, A=40; the representation of 40 is A, so A is called the variable. For storing information, a variable can be called "containers".
Rules for variable
1. Add a $ (dollar sign) in front or before the variable name.
For example: $No_of_oranges
2. The PHP cannot begin with numerals; despite the fact of adding the dollar sign ($) in front of the variable name. The variable name must begin with alphabets or underscore sign(_).
3. The PHP variable may contain the following characters:
5. Variable name can be any length long.
Variable Types:
1. Scalar types:
Constants
PHP constants are similar to variable but they cannot be changed when the script is executed.
The basic features of a constant that distinguish them from a variable are:
Pre-defined variables
Pre-defined variables are already installed or defined variables, and PHP provides a large number of pre-defined variables to its users. This pre-defined variables are called "super globals".
The pre-defined variables are given below:
A variable is a representation of a value. Let's take for instance, A=40; the representation of 40 is A, so A is called the variable. For storing information, a variable can be called "containers".
Rules for variable
1. Add a $ (dollar sign) in front or before the variable name.
For example: $No_of_oranges
2. The PHP cannot begin with numerals; despite the fact of adding the dollar sign ($) in front of the variable name. The variable name must begin with alphabets or underscore sign(_).
3. The PHP variable may contain the following characters:
- Numerals: (0-9)
- Alphabets: (A-Z) or (a-z)
- Underscore: (_)
5. Variable name can be any length long.
Variable Types:
1. Scalar types:
- Boolean
- Integer
- Float
- String
- Object
- Array
- Resource
- Null
<?php
$string_value="hello simply lecture! ";
$integer=126;
$float=3.658;
$boolean=true;
$array=array(1,2,3);
$object=new subject_name();
$null_variable=NULL;
?>
Constants
PHP constants are similar to variable but they cannot be changed when the script is executed.
The basic features of a constant that distinguish them from a variable are:
- Constants don't require the $ (dollar sign) before their names
- Constants are usually uppercase that distinguish them from normal variable
- define() is used to define a constant, it requires the name and the value of the name.
Example:
define("subject name","simply lecture");
- You can check if a given constant name exist or not.
Example:
if (defined("subject_name"))
echo "constant subject_name exist";
Pre-defined variables
Pre-defined variables are already installed or defined variables, and PHP provides a large number of pre-defined variables to its users. This pre-defined variables are called "super globals".
The pre-defined variables are given below:
- $GLOBALS - All variables available in global scope.
- $_SERVER - Server and execution environment information.
- $_GET - HTTP GET variable.
- $_POST - HTTP POST variable.
- $_FILES - HTTP File upload variable.
- $_SESSION - Session variable.
- $_REQUEST - HTTP Request Variable.
- $_ENV - Environment variable.
- $_HTTP COOKIES - HTTP cookies.
Comments
Post a Comment