PHP Data Types

Variable can be store data - data can be string ,integer,float,boolean ,anything data store in variable

PHP support following data types

  1. String
  2. Interger
  3. Float ( float number also call double number )
  4. Boolean
  5. Array
  6. Object
  7. Null
  8. Resourse

PHP String

String can be sequence of charectors or word like "Hello Word"

Tips : PHP string written inside double or single quotes

Example

<?php

$str = "Hey how are you";

$str1 = "I am fine ";

echo $str;

echo "<br>";

echo $str1;

// You can check what type of data by var_dump()

echo "<br>";

echo var_dump($str);

?>

Try Code

Tips : If you write variable inside string you should be write string double quotes

Example

<?php

$a=15;

echo "The number is : $a";

//if you try to write single quotes it consider as like text

?>

Result

The number is :15



PHP Interger

PHP interger is a number like 1,0,10,452,  .......

Tips : You can not write integer within single or double quotes

Tips : If you write interger within single or double quotes PHP consider as string

Tips :Interger does not have decimal point

Example

<?php

$a = 12;

$b = 8;

// Adding variable

$z = $a + $b;

echo $z;

// You can check data type by var_dump()

echo "<br>";

echo var_dump($z);

?>

Result

20

int(20)




PHP Float Number

Float number is decimal number like as 0.3 , 42.54 ,600.45

Example

<?php

$a = 42.15;

$b = 46.02;

echo var_dump($a);

echo "<br>";

echo var_dump($b);

?>

Result

flot(42.15)

float(46.02)



PHP Boolean

Boolen can be true or false

Example

<?php

$x = true;

$y = false;

echo var_dump($x);

echo "<br>";

echo var_dump($y);

?>

Result

bool(true)

bool(false)



PHP Array

Array is a data structure that store an arbitrary number of data in a single variable

Example

<?php

$arry  = ["apple","pears","orange"];

echo $arry[1];

echo "<br>";

echo var_dump($arry);

?>

Result

pears

array(3){[0]=>string(5) "apple" [1]=>string(5) "pears" [2]=>string(6) "orange"}