Variables

Variables are used to Store Information to be referenced and manipulated in a program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as Containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program...

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.
  • 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 before they are assigned have default values.
  • PHP does a good job of automatically converting types from one to another when necessary.
  • PHP variables are Perl-like.

PHP has a total of eight data types which we use to construct our Variables.
  1. Integers − are whole numbers, without a decimal point, like 4195.
  2. Doubles − are floating-point numbers, like 3.14159 or 49.1.
  3. Booleans − have only two possible values either true or false.
  4. NULL − is a special type that only has one value: NULL.
  5. Strings − are sequences of characters, like 'PHP supports string operations.'
  6. Arrays − are named and indexed collections of other values.
  7. Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
  8. Resources − are special variables that hold references to resources external to PHP (such as database connections).
The first five are simple types, and the next two (arrays and objects) are compound - the compound types can package up other arbitrary values of arbitrary type, whereas the simple types cannot.

Comments

Popular posts from this blog

Differences

Uses of PHP

What is PHP?