PHP Data Types

PHP data type is used to hold the various types of data or value.  There are three types of data types in PHP. It is a loosely data typed language, so there is no need to declare data type like int,float etc. InPHP,there are some function to check data type and its value.
  • gettype(): It is used to check only data type.
  • var_dump(): It is used to check the size and data type.
Example1:
<?php
$var = 60;
echo "60 is: ".gettype($var);
echo "<br>";
// ------------------------------
$var = 1000.56;
echo "1000.56 is: ".gettype($var);
echo "<br>";
// ------------------------------
$var = "PHP";
echo "PHP is: ".gettype($var)
?>
Output 60 is: integer 1000.56 is: double PHP is: string Example2
<?php
$num=100;
$str="Hello PHP";
$f=3.40;
var_dump($num);
var_dump($str);
var_dump($f);
 //var_dump($num,$str,$f);
?>
Output int(100) string(9) "Hello PHP" float(3.4) Example of Array:
<?php
$cars = array("You","Are","Good_Developer!");
var_dump($cars);
?>
Output array(3) { [0]=> string(3) "You" [1]=> string(3) "Are" [2]=> string(14) "Good_Developer" } Example of Object.
<?php
class Course {
function Course() {
        $this->Course = "PHP";
    }
}
// create an object
$lang = new Course();
// show object properties
echo $lang->Course;
?>
Output PHP Example5.
<?php
$x = "Hello PHP!";
$x = null;
var_dump($x);
?>
Output NULL Example: 6
<?php
$con = mysqli_connect("localhost","root","","users");
?>
Note: It is used in database. Following are the predefine functions to Check data type
Predefine Data type Description
is_int( ) To check the value is integer or not.
is_float( ) To check the value is float or not.
is_numeric( ) To check the value is either integer or float.
is_string( ) To check the value is string or not.
is_bool( ) To check the value is Boolean or not.
is_object( ) To check the value is object or not.
is_null( ) To check the value is null or not.

Related Topics

PHP natsort() Function

PHP natsort() Function The natsort() function in PHP Sort an array using a case insensitive "natural order" algorithm while maintaining the keys. Syntax natsort ( array &$array ) Parameter array(required)- This parameter represents the input array. Return This parameter returns a Boolean value TRUE on success or FALSE on...

1 minute read.

PHP is_object() Function

The is_ object() function in PHP finds whether the specified variable is an object or not. It returns a Boolean value TRUE if the specified var is an object else it returns FALSE. Syntax is_object(mixed$var) var(required)- This parameter represents the...

1 minute read.

PHP soundex() Function

PHP soundex() Function The soundex() function in PHP Calculates the soundex key(four character long alphanumeric string that represent English pronunciation of a word) of a string. Syntax soundex ( string $str ) Parameter str(required) – This parameter represents the input string. Return This function returns the soundex...

1 minute read.

PHP rtrim() Function

PHP rtrim() Function The rtrim() function in PHP is used to strip off the whitespace (or other characters) from the end of a string. If the second parameter is not specified, this function will strip are...

1 minute read.

PHP print_r() Function

PHP print_r() Function The print_r() function in PHP displays the information stored in a variable. Syntax print_r (mixed $expression [, bool $return] ) Parameter expression(required)- This parameter represents the expression to be printed. return(optional)- This parameter is used to store the output of...

2 minutes read.

PHP Operator

PHP Operator is used to perform operations on variable and values. Following are the types of Operator: PHP Arithmetic Operator PHP Arithmetic operator is used for arithmetical operations, such as addition, subtraction, multiplication...

2 minutes read.

PHP is_int() Function

The PHP is_int() function in PHP is used to  find whether a variable is an integer or not. It returns a Boolean value true if the parameter var is integer else it...

1 minute read.

PHP count() function

PHP count() function The count() function in PHP is used to count all elements in the specified array or something in an object. Syntax count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )   Parameter array_or_countable(required)– This parameter represents the input array or countable object. mode(optional)- This...

2 minutes read.

PHP settype() Function

PHP settype() Function The settype() function in PHP is used to set the type of variable var to type. Syntax settype ( mixed &$var , string $type ) Parameter var(required)- This parameter represents the variable being converted. type(required)- This parameter represents the type of variable that is needed.  The possible values of type are...

1 minute read.

PHP array_values() Function

PHP array_values() Function The array_values () function in PHP returns all the values from the array and indexes the array numerically. Syntax array_values ( array $array ) Parameter array(required)- This array represents the input array. Return This function returns an indexed array of values. Example 1 Output Input Array: Array ...

1 minute read.

PHP array_pop() Function

PHP array_pop() Function The array_pop() function in PHP pops or removes the last element from the array shortening the array by one element. Syntax array_pop ( array &$array ) Parameter array(required)- This parameter represents the input array to get the value...

1 minute read.

PHP array_keys() Function

PHP array_keys() Function The array_keys() function  in PHP is used to return all the keys, numeric and string from the given array. Syntax array_keys ( array $array ) or array_keys ( array $array , mixed $search_value [, bool $strict = FALSE ] )  Parameter array(required)- This parameter specifies the input array search_value(optional)- This parameter specifies a value, where...

1 minute read.

PHP fprintf() Function

PHP fprintf() Function The fprintf() function in PHP outputs a formatted string. This function operates as printf() but accepts an array of arguments, rather than a variable number of arguments. Syntax vprintf ( string $format , array $args ) Parameter format(required)- This parameter specifies the string and how to...

4 minutes read.

PHP htmlspecialchars_decode() Function

PHP htmlspecialchars_decode() Function The htmlspecialchars_decode() function in PHP convert some predefined HTML entities to characters. The some predefined HTML entities that will be decoded are as follows: &amp; OR & (ampersand)&quot; OR " (double quote)&#039;...

2 minutes read.

PHP array_chunk() Function

PHP array_chunk() Function The array_chunk() function in PHP is used to split an array into chunks where the last chunk may contain less than size elements. Syntax array_chunk ( array $array , int $size [, bool $preserve_keys ]...

1 minute read.

PHP is_real() Function

The PHP is_real () function in PHP is used to find whether the type of the specified variable is a float or not. It returns a Boolean value true if the parameter...

1 minute read.

PHP quoted_printable_decode() Function

PHP quoted_printable_decode() Function The quote_printable_decode() function of PHP converts a quoted-printable string to an 8 bit string. It works similar to imap_qprint(), except this one does not require the IMAP module to work. Syntax quoted_printable_decode ( string $str ) Parameter str(required)- This parameter represents the...

1 minute read.

PHP sizeof() Function

PHP sizeof() Function The sizeof() function in counts all elements and return the size of the array. This function is an alias of count(). Syntax sizeof( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )  Parameter array_or_countable(required)– This parameter represents the input array or countable object. mode(optional)-...

1 minute read.

How to use Date and Time in PHP

HOW TO USE DATE AND TIME IN PHP: PHP time and date function  informs us about current date and time. it can be manipulated also. How time() function works: The time() function...

2 minutes read.

PHP key() Function

PHP key() Function The key() function in PHP fetches a key from an array and returns the index element of the current array position. Syntax key ( array $array ) Parameter array(required)- This parameter represents the input array. Return This function returns the key of the...

1 minute read.