In this article you can learn the PHP data types. Basically you can find eight data types in PHP.
A scalar is a “single” value – integer, boolean, float , perhaps a string
compound is made up of multiple scalars
false are the values for boolean data type.
How do you declare boolean value in PHP?
<?php $is_saved = true; $is_admin = false;
You can use
False to indicate boolean values since the keyword is case-insensitive
PHP treats the following values as
'') and the string “0”
SimpleXMLobjects created from attribute less empty elements
Integer data types hold whole numbers like …,-1,0,1,2,3 …. . The range of the numbers depends on the platform.
Normally, it lies from -2,147,438,648 to 2,147,483,647. It’s equivalent to 32 bits signed.
$number = 20
Integer can be decimal (base 10), octal (base 8), or hexadecimal (base 16).
$dec_num = 243 $oct_num = 0243; $hex_num = 0x45;
String data type can hold non numeric data.
String can hold charter (“A”) or series or characters (“Apple”). You can use single quote (‘ ‘) or double quote (” “)
$str_varaible = 'Apple' $str_variable = "Apple"
Floating-point numbers are the decimal numbers you find and you can have the positive numbers as well as the negative numbers.
<?php $n1 = 13.89; ?>
There are two types of compound data types in PHP called Array and Object
What is an Array?
Array is a variable that can hold more than one value at a time. You can define an array to hold marks of a student, best selling product list, etc.
Following example, you can create $week array to hold the days of the week
<?php $week = array("Sun", "Mon", "Tue","Wed","Thu","Fri"."Sat"); echo count($week); ?>
In PHP, there are three types of arrays
To check data type of any variable, you can use the function gettype() provided by PHP.
You can see the following examples
$value = 'Hello Word'; echo "Data type is - ".gettype($value); $value = 1.2; echo "Data type is - ".gettype($value);