PHP Variables
The major way to reserve information in the middle of a PHP program is by utilizing a variable. Here are the most important things to know about variables in PHP. All Variables in PHP are denoted with a leading dollar sign ($). The value of a variable is the value of its most recent assignment.The main way to store information in the middle of a PHP program is by using a PHP variables.
Important things about PHP variables :
- All variables in PHP are denoted with a leading dollar sign ($).
- The value of a variable is the value of its most recent assignment.
- Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.
- Variables can, but do not need, to be declared before assignment.
- Variables in PHP do not have intrinsic types – a variable does not know in advance whether it will be used to store a number or a string of characters.
- Variables used previously they are assign have old values.
- PHP does a excellent work of automatically transfer types from one to another when necessary.
- PHP variables are Perl-like.
Rules for PHP variables :
- A variable starts with the $ sign, followed by the name of the variable
- A variable name must start with a letter or the underscore character
- A variable title can’t be generate from a number
- Variable title is case-sensitive
PHP Supports following Data types :
- Integers − are whole numbers, without a decimal point, like 4195.
- Doubles − are floating-point numbers, like 3.14159 or 49.1.
- Booleans − have two feasible values either true or false.
- NULL − is a particular kind that only has value: NULL
- Strings − are sequences of characters, like ‘PHP supports string operations.’
- Arrays − are named and indexed collections of other values.
- Objects − are occurence of programmer-defined classes, which can package up both alternative types of values and functions that are specific to the class.
- Resources − are special variables that hold references to resources external to PHP (such as database connections).
Now we discuss the scope of variables with the PHP Training in Chandigarh
PHP Variables Scope :
In PHP, variables can be announce anywhere in the script.The range of a variable is the part of the script where the variable can be referred/used. PHP has three different variable scopes:
- Local Variable
- Global Variable
- Static Variable
Local Variable : A variable declared in a function is considered local that is, it can be referred solely in that function. Any assignment surface of that function will be examine to be an totally dissimilar variable from the one contained in the function Global Variable : In programming, a global variable is a variable with global scope, meaning that it is visible (hence accessible) throughout the program, unless shadowed. The set of every global variables is known as the global environment or global state. Static Variable : static can also be used to define static variables and for late static bindings.Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. A property announce as static cannot be accessed with an instantiated class object (through a static method can). If you want to learn more about variables then join the PHP Training in Chandigarh which is provided by CBitss Technologies at sector-34 A .