How to Install Operating System ??Complete Guide Installing The Operating System

PHP Data Types Along With Examples

e-bookcomputer.com – This tutorial discusses PHP Data Types, what are data types? PHP Data Types is the type or characteristic of a value that is accommodated on a variable, in all programming languages must have data types that are generally not different. In PHP itself, there are 8 (eight) types of data types that can be used to determine a value that is accommodated.

In some programming languages to determine the type of data type it must first declare it, in contrast to PHP, where writing data types do not need to be declared because PHP will automatically read the type of data type of a value, here are the types of data types in PHP and their explanation.

Before going forward, there are a number of articles that you might be looking for.

Read too :

Integer Data Type

Integers are integer data types, can be either positive or negative integers, but integers support octal, decimal and hexadecimal numbers. Actually, the range of data types in PHP in the form of Integers is the same as the LONG data type in the C programming language, except that in C language standards it does not determine the length of the value of this data type, so it is possible for some systems to see different values.

<?php
     $decimal = 1337;
     echo "This is a decimal number: $decimal";
?>

… output

PHP Data Types
PHP Data Types

Example of Writing Octal Numbers

To write integer data types in the form of octal numbers must be preceded by a number 0 (zero) in front of it, for example.

<?php
     $octal = 0755;
     echo "Convert 0755 octal numbers to decimals $octal ";
?>

… output

PHP Data Types
PHP Data Types

Example of writing hexadecimal numbers

To return an integer data type in the form of hexadecimal numbers, it must start with “0x” in front of the number, for example:

<?php
     $hexa = 0xFF;
     echo "Convert hexadecimal numbers 0xFF to decimal $hexa";
?>

… output

PHP Data Types
PHP Data Types

Float Data Types

Float data types can be called Floating-points and real numbers or commonly referred to as court numbers, for example, 2.5, 4.5 and others, examples of using float data types in PHP:

<?php
     $a = 4.5;
     $b = 3.5;
     $result = $a + $b;
     echo "Example of the sum of float data types 4.5 and 3.5, results: $result";
?>

… output

PHP Data Types
PHP Data Types

String Data Type

Data string types are used to hold values in the form of text and characters, strings can be a word or sentence because the type of string data types are text and characters, so arithmetic operations on this type of data type cannot be calculated, for example:

<?php
     $string = 'This is a string data type';
     echo $string;
?>

… output

PHP Data Types
PHP Data Types

Boolean Data Type

The type of boolean data type is the type to determine the logic of true or false conditions by using the values TRUE and FALSE, this type of data type does not affect uppercase and lowercase letters, besides to represent conditions the boolean data type can also use a value of 1 0 (FALSE), for example:

<?php
     $a = TRUE;
     $b = FALSE;
     if ($ a == TRUE)
     {
        echo 'Variable $ a is worth TRUE';
     }
     echo '<br />';
     if ($ b == FALSE)
     {
        echo 'Variable $ b is FALSE';
     }
?>

… output

PHP Data Types
PHP Data Types

Array Data Type

An array is a variable that consists of a set of data where the data has the same data type and each data is stored at different memory addresses, many of which can be used by using arrays, for example to group the same data for example city names, years, and others. Here’s how to write an array:

<?php
     $data = array ('Jakarta', 'Bogor', 'Depok', 'Tangerang', 'Bekasi');
     echo 'This is an example of the name of the Jabodetabek city arranged in an array: <br />';
     print_r ($data);
?>

… output

PHP Data Types
PHP Data Types

Before proceeding, there are a number of articles that might be looking for.

Also read :

Sending
User Review
0 (0 votes)

Add a Comment

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