What are PHP Data Types ?

When we take a look at our previous lesson, PHP Variables, we actually defined something without a data type. In fact, we have made these parts according to a data type. If we define these values, PHP automatically determines the type.


In order to see these automatically determined variable types and to browse the variable types in PHP, we will print the values ​​we defined with something else instead of the echo tag and take a look at the PHP data types.


PHP Data Types

In fact, learning PHP data types is very simple. We will learn about the data type by using another tag, not the echo tag, to learn the data type of anything we write to this variable. In a way, we had to specify the type of name we would assign a variable to a variable in C, C #, Delphi and many other programming languages. In PHP, however, each value you assign to the variable is automatically assigned according to your own assignment.


PHP Data Types is:

  1. String
  2. Integer
  3. Float
  4. Boolean
  5. Array

as. If you are already familiar with these values ​​I should make a brief explanation:

Data TypeDescription
StringIt consists of characters. For example, if we write our name, this is a string value.
IntegerAn integer data type, Integer, is a number between -2,147,483,648 and 2,147,483,647.
FloatFloat refers to fractional numbers. If you type a decimal number, its data type is Float.
BooleanBoolean returns true and false. It means whether or not there is a transaction.
ArrayIf the Array data type, if we assign more than one specific thing to that variable, then the Array data type will work.


We have now learned what the data types do in PHP. However, as we did in our previous lesson, after writing the basic php code, creating a variable and assigning a value to this variable, then we need to use the var_dump code shown below to display the data type of this variable on the screen.


$myname ="gokmen";
// In the above section, the screenshot will be printed gokmen value and string.

$mynumber1 =10;
// In the above section, the number 10 will be written and the data type of this number is integer.

$mynumber2 =10.5;
// In the above section, the number 10.5 will be written and the data type of this number will be printed as float.

$mycars =array("Volvo","BMW","Ford");
// In the above section, we have given more than one value and it will be printed on the screen and which data type will be displayed.


When you write the variable name using the var_dump command, your screen view will write this data exchange data type. PHP requires that we automatically define the data type without having to define it. In this way, if you want to see PHP data hints in PHP now we can do it because we have just learned, if you want to display the variable “echo” command you are aware that we use.


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button