Definition- Data type is a pre-defined text that is used with assigning a variable in your PHP Script. Instead of PHP Script, you will see this point(Data-type) in most programming languages. We will see these points in detail.
Internal Data Types -: Internal data-type is a type of data-type that is used internally without knowing the Programmer or Developer. PHP provides this functionality to the developer, to develop web application programs without declaring different data types. This process works internally to convert data type according to the developer’s data.
Hello my all dear visitors, welcome again in this domain(bittutech.com). In this PHP Tutorial, we are going to see What is Data types or Internal Data types?
We are needed to understand why PHP gives us the functionality of Internal Data-Types?
PHP is a loosely-type scripting language which means we can declare any type of data into the variable without assigning their data-type. During interpretation, PHP changes your variable type according to your declared data into that variable.
Working with PHP Variable
To work with PHP variable, you don’t need to specify the data-type with the variable. We can use or write the $(dollar) symbol before specifying any variable name.
Example – $name, $DOB, $Father_name, $mother_name
Storing Data in Variables
In PHP, as in other languages, you can assign data to variables. PHP lets you store numbers and text to those variables, as in these examples:
$pi=3.1415926535 $name=Sunny $fish="haddock"
Unlike some other online languages, such as Java, PHP doesn’t insist that you create different types of variables for different types of data. Here’s how these variables might be created in Java:
Double pi=3.141592653589793; Int marks= 98; String fish="haddock"; String name="Prajjwal";
Note – : “=” equal sign is the assignment operator in PHP language.
String interpolation is a quick shortcut, allowing you to pop the value of a variable into a double-quoted(not single-quoted string).
You can display the value in a variable like this:
<?php $cheeseburgers=1; Echo "Current number of cheeseburgers :", $cheeseburgers, "<br>"; ?> Output : Current number of cheeseburgers : 1 OR You can also display the value in a variable like string interpolation as - <?php $cheeseburgers=1; Echo "Current number of cheeseburgers : $cheeseburgers<br>"; ?> Output : Current number of cheeseburgers : 1
When you use interpolation, you only have to place the variable whose value you want to insert inside a double-quoted(not single-quoted) text string.
Creating variable Variables
While discussing variables, it’s also worthwhile to discuss variable variables. No, that’s no typo –
PHP lets you create variable variables – which are variables that hold the name of another variable.
Example-: $cheeseburger=1; $burgertype="cheeseburger"; echo "Number of burger is -: ".$cheeseburger; echo "Number of burger is -:".$$burgertype;
Both echo statement will give the same result.
Creating Constants -:
Sometimes, you don’t want a data item to be a variable. For example, the value of pi, 3.1415926535, shouldn’t change. If you created a variable named $pi, something in your code might assign a new value to $pi by mistake. The thing to do here is to create a constant, whose value can’t be modified.
You create a constant in PHP with the define function, passing define the name of the constant you want to create and the value you want to give it, such as to define(“PI”, 3.1415926535).
That creates a constant named PI – and that’s case-sensitive: PI is not the same as pi(if you want to make a constant non-case-sensitive, you can pass a value of TRUE like this define(“PI”, 3.1415926535, TRUE). you don’t use a $ in front of the name because doing so would make it a variable.
Let’s go ahead and look at the example of how to create constants and variables?
<!DOCTYPE HTML> <html> <head> <title> Create Constants and Variables </title> </head> <body> <?php define("PI",3.141,TRUE); $name="Prajjwal Singh"; echo "My Name is-:".$name."</br>"; echo "The value of Constant".$PI."<br>"; ?> </body> </html>
My dear visitors, this is it for now. I hope you would have enjoyed this article. After reading this PHP article, you can learn more topics related to PHP article, you can read those article. Thank you so much for giving love and support to this article. You can get more updates about posts and articles by joining us on social network sites.