We have learned in the last tutorial, about Reference of variable. Now, we will discuss Data Types in PHP.
The very first question in our mind is what is data type?
In simple language, if variables are container then data type is the type of container. type of container actually tells what kind of stuff can be put in it. For example, you don’t want to put cookies in a bottle similarly you don’t want to store an integer value in a variable of data type String.
Basically data types in PHP can categorized into 3 types:
First, we will take the example of an integer,
They are whole numbers, without a decimal point, like 4195. They are the simplest type They correspond to simple whole numbers, both positive and negative. Integers can be assigned to variables, or they can be used in expressions, like so –
An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
<?php
$int=”12345 <br>”;
$onemore_int = -12345 + 12345;
echo $int_var;
echo $another_int;?>
OUTPUT:
123450
A float (floating point number) is a number with a decimal point or a number in exponential form.
It is also called numeric data type. A number with a fractional component.
They like 3.14159 or 49.1. By default, doubles print with the minimum number of decimal places needed. For example, the code −
<?php
$float=20.2534;
echo $float;?>
OUTPUT:
20.2534
<?php
$abc = “PHP Tutorials on”;
$xyz = ‘Tekraze!’;echo $abc;
echo “<br>”;
echo $xyz;
?>
OUTPUT:
PHP Tutorials on
Tekraze!
The escape-sequence replacements are −
- \n is replaced by the newline character
- \r is replaced by the carriage-return character
- \t is replaced by the tab character
- \$ is replaced by the dollar sign itself ($)
- \” is replaced by a single double-quote (“)
- \\ is replaced by a single backslash (\)
if (TRUE)
print(“This will always print
“);else
print(“This will never print
“);
<?php
$arr= array(“Volvo”,”BMW”,”Toyota”);
var_dump($arr);
?>
<?php
class hello {
function hello() {
$this->model = “TEKRAZE”;
}
}// create an object
$abc = new hello();// show object properties
echo $abc->model;
?>
OUTPUT:
TEKRAZE
1. Resource
2. Null
<?php
$conn=mysqli_connect(“localhost”,”root”,”password”);
?>
<?php
$x = “Tekraze!”;
$x = null;
var_dump($x);
?>
OUTPUT:
null
If you like this tutorial please share it with your friends, colleagues, and your relatives, keep visiting, and be a part of the Tekraze family. If you have any problem with this tutorial please comment in the comment box and if you have any suggestions regarding this then please tell us.
This post was last modified on November 27, 2023 2:25 am
Struggling with a locked Samsung Galaxy or Note smartphone? Remove KG Lock, a U.S.-based company,…
When you open Adobe Photoshop for the first time, it's easy to click around in…
Social Media Influencer apps for mobile With the increasing number of social media platforms and…
Microsoft Dynamics 365 is a suite of Business Applications from Microsoft that covers the traditional…
While torrents and peer-to-peer (P2P) file sharing have long been popular for data transfer, concerns…
In today's increasingly interconnected world, reliable communication is paramount. But what happens when emergencies strike…
This website uses cookies.
View Comments
Saved as a favorite!, I really like your blog!
Thanks