PHP DATA TYPES

PHP DATA TYPES
What is variable in programming?
The answer is simple variables are symbols that refer to something,in simple words the value of the variable changes depend on scenarios.
For example 
         M = 20;

Here we have a variable M and it’s value is 20.
Now let’s start with php variables their are some to give the name to variables in php .let’s go over them before we start working with them, First and foremost php variable names must start with a $ symbol and an expression that expression can be letter or underscore .php variable can contain letter,number,underscore and dashes.no space are allow between names and they are case sensitive mean lowercase and uppercase letters matter and variable name should be written as it is.
In php there are several types of variables each used for storing different types of in or values. Given below is the list of all variables that are available in php.

  • String.
  • Integer.
  • Float.
  • Boolean.
  • Array.
  • Object.
  • NULL.
  • String:
A string is a sequence of characters, like "Hello world!".A string can be any text inside quotes. You can use single or double quotes.
Example
$X = "hello world";
$Y = "hello world";
Integer:
An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Rules for integers:
  • An integer must have at least one digit
  • An integer must not have a decimal point
  • An integer can be either positive or negative
  • Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation 
Example:
 $x = 8756;car_dump($x);
Float:
A float (floating point number) is a number with a decimal point or a number in exponential form.
Example:

$x = 1.785;
var_dump($x);
Boolean:
A Boolean represents two possible states: TRUE or FALSE.
Example:
$x = true;
$y = false;

Array:
An array stores multiple values in one single variable.
Example:
$new_array = array (“hello”, “World”);
var_dump($new_array);

 Object:
An object is a data type which stores data and information on how to process that data.In PHP, an object must be explicitly declared.First we must declare a class of object. For this, we use the class keyword. A class is a structure that can contain properties and methods
Example:
<?php
class class_room {
  function student() {
$this->student = "student1";  }
// create an object
$herbie = new class_room();
// show object properties
echo $herbie->student;
?>

NULL:
Null is a special data type which can have only one value: NULL.A variable of data type NULL is a variable that has no value assigned to it.
Example:
$x = “hello World”;
$x = null;
var_dump($x);

Next we will learn about conditional statements and how they work in php. conditional statements are used to evaluate behaviour of a program based on whether the condition is true or false

Comments