phpicoder Nov 2, 2021 php

Hello friends, in this tutorial, we will learn about data types in php and it supports 8 different data types, which are classified into 3 main types.

Four scalar types:

  1. boolean
  2. integer
  3. float
  4. string

Four compound types:

  1. array
  2. object
  3. callable
  4. iterable

And finally two special types:

  1. resource
  2. NULL

The type of variable is not usually set by the programmer; Instead, it is determined by PHP based on the runtime in which that variable is used.

Example:

<?php
  $var_bool = TRUE;   // a boolean
  $var_str  = "foo";  // a string
  $var_str2 = 'foo';  // a string
  $var_int = 12;     // an integer
  $var_float = 12.12;  // a float
  $var_null = null;   // a null
  $var_array = array ("php", "java", "android", "ios");  // a array

  echo gettype($var_bool); // prints out:  boolean
  echo gettype($var_str);  // prints out:  string
?>

Note:- Resources PHP does not have a specific data type. By default, this is used to store some function calls or references to external PHP resources

I hope this tutorial help for you.