Types of Variable Types used in PHP

The main way to store information in the middle of a PHP program is by using a variable. Here are the most important things to know about variables in PHP.

  • All variables in PHP are denoted with a dollar sign ($varname).
  • The value of a variable is the value of its most assigned.
  • All the variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.
  • 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:

  • Integers: are whole numbers, without a decimal point, like 4195.
  • Doubles: are floating-point numbers, like 3.14159 or 49.1.
  • Booleans: have only two possible values either true or false.
  • NULL: is a special type that only has one value: NULL.
  • Strings: are sequences of characters, like 'PHP supports string operations.'
  • Arrays: are named and indexed collections of other values.
  • Objects: are instances of programmer-defined classes, which can package up both other kinds 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).

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.

Advantages Of NCERT, CBSE & State Boards Solutions For All Subjects

  • All the NCERT Solutions have been prepared by academic experts having 10+ years of teaching experience.
  • They have prepared all the solutions in simple and easy language, so that each and every student can understand the concepts easily.
  • All the solutions have been explained step to step wise in details with better explainations.
  • Students can also use these question and answers for your assignments and in homework help.
  • All the solutions have been explained in detail and the answers have been compiled in a step-wise manner.
  • All the question and asnwers are commonly prepared according to the Latest Syllabus of Board Education and Guidelines.
  • Students can know about the various types of questions asked in the exams with the help of these solutions.

Top Engineering Courses