How many Data Types in php

 In PHP, there are eight basic data types:

  1. Integer: A whole number, either positive or negative
  2. Float: A number with a decimal point, also known as a "floating point number"
  3. String: A sequence of characters, enclosed in single or double quotes
  4. Boolean: A value that can be either true or false
  5. Array: A collection of values, indexed by keys
  6. Object: An instance of a class, which can have its own properties and methods
  7. Resource: A special type that represents a connection to an external resource, such as a database connection or a file handle
  8. NULL: A special type that represents the absence of a value

PHP also supports several other specialized data types, such as callables, iterators, and generators.


In PHP, there are eight basic data types:

  1. Integer: A whole number, either positive or negative For example:
$a = 123; // positive integer $b = -456; // negative integer

2. Float: A number with a decimal point, also known as a "floating point number" For example:

$c = 3.14; // positive float $d = -2.71828 // negative float

3. String: A sequence of characters, enclosed in single or double quotes For example:

$e = 'Hello, world!'; // string in single quotes $f = "Goodbye, world!" // string in double quotes

4. Boolean: A value that can be either true or false For example:

$g = true; // boolean true value $h = false; // boolean false value

5. Array: A collection of values, indexed by keys For example:

$i = array(1, 2, 3, 4, 5); // numeric array $j = array('red', 'green', 'blue'); // associative array

6. Object: An instance of a class, which can have its own properties and methods For example:

class Person { public $name; public $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } public function getName() { return $this->name; } public function getAge() { return $this->age; } } $k = new Person('John', 30); // instance of the Person class

7. Resource: A special type that represents a connection to an external resource, such as a database connection or a file handle For example:

$link = mysqli_connect('localhost', 'username', 'password', 'database'); // database connection $file = fopen('data.txt', 'r'); // file handle

8. NULL: A special type that represents the absence of a value For example:

$l = null; // null value

Popular posts from this blog

Yii Framework In Update Time View Image In Form

Add a new column to existing table in a migration

Ajax Toggle(on/off) on-click Update