welcome to tutorialfamily

php datatype

Php data type – variable store different type of data.

Different data type can do different things.


php data type

Data type are give below.

  • String :
  • Integer :
  • Boolean :
  • Float :
  • Array :
  • Null :
  • Object :

php string

A string is a sequence of characters, like “Hello, how are you!”

A string of text should be in single or double quotes.


string data type



<!DOCTYPE html>
<html>
<head>
	<title>constants example</title>
</head>
<body>
<?php
	$a = "Hello";
	$b = 'How are you!';

	echo $a;
	echo "<br>";
	echo $b;
?>
</body>
</html>

output

php Integer

An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.

  • An integer must have one value
  • An integer positive or nagative
  • An integer must not have decimal point
  • An integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2)
  • var_dump() function returns the data type and value

php integer



<!DOCTYPE html>
<html>
<head>
	<title>php integer</title>
</head>
<body>
	<?php
		$a = 4321;
		var_dump($a);
	?>
</body>
</html>

output

php float

float data type is a use for point number.


php float



<!DOCTYPE html>
<html>
<head>
	<title>php float</title>
</head>
<body>
<?php
	$a = 15.542;
	var_dump($a);
?>
</body>
</html>

output

php boolean

boolean represent the two statement. True or False


boolean datatype



<!DOCTYPE html>
<html>
<head>
	<title>boolean datatype</title>
</head>
<body>
   <?php
      $x = true;
      $y = false;
   ?>
</body>
</html>

Array datatype

Multiple value store in single variable.

Below given multiple car name store in single variable.


Array datatype



<!DOCTYPE html>
<html>
<head>
	<title>array datatype</title>
</head>
<body>
<?php
	$car = array("Oddi","Honda","Tata");
	var_dump($car);
?>
</body>
</html>

output

Object datatype

Object datatype store value and information.

First of we need to declare class of object.

Class contain object value.

Then create a new object.

Pass the value in object by statement


Object datatype



<!DOCTYPE html>
<html>
<head>
	<title>object datatype</title>
</head>
<body>
<?php
class Bike {
    function Bike() {
        $this->model = "Xtream";
    }
}

// create an object
$xbike = new Bike();

// show object properties
echo $xbike->model;
?>
</body>
</html>

output

Null datatype

Null datatype contain null value.

Variable have no any store the value.

If variable created without any value, It mean this variable assigned the Null value.


Null datatype



<!DOCTYPE html>
<html>
<head>
	<title>Null datatype</title>
</head>
<body>
<?php
	$a = "Hello How are you!";
	$a = null;
	var_dump($a);
?>
</body>
</html>

output

Our Content