+1 313 880 3184

PHP Tutorials

$100.00

Data Types training

Prerequisites Data Types: HTML

Variables or datatype in php language, like other programming languages, have different types, each with its own application. The following list of data type tutorials shows the different types of PHP language data:

  • Text variable or string
  • Ordinary numeric variable or integer
  • Float numeric variable, also called double
  • True or False variable or Boolean
  • Array variable
  • Object variable
  • Null variable
  • Resource reference

A text variable, or String, is a set of consecutive characters such as ” Hello World !”
String text variables must be defined within a pair or “”. Like the following example code:

<!--?php
$x "Hello world!";
$y 'Hello world!';
echo $x;
echo "<br-->";
echo $y;
?>

A simple numeric variable or integer is a non-decimal number in the range of -2.147.648 to 2.147.647. In determining integer numeric variables, you must observe the following points in Data Types:

  • An integer numeric variable must have at least one numeric digit.
  • Integer numeric variables cannot have decimals.
  • An integer numeric variable can be positive or negative.

In the following practical example, the variable x is an integer. The var_dump () function returns both the value and the type of the variable:

<!--?php
$x = 5985;
var_dump($x);
?-->

A decimal or float variable consists of a numeric part with a decimal or exponential part (fraction). In the example code below, the variable x is defined as a float decimal variable. Then, using the var_dump () function, we show the type and value of the variable in the Data Types in the output:

<!--?php
$x= 10.365;
var_dump($x);
?-->
A Boolean variable can have a true value of true or false false, such as the following example code:
$x= true;
$y= false;
Boolean variables are commonly used in conditional expressions. In future lessons, we will teach you how to work with conditional statements.
An array is a set of two or more variables of the same type that are defined within a single variable.
In the following practical example code, we show how to define and value the $ Car array variable, and then print its value and type in the output using the var_dump () function:
<!--?php
$carsarray("Volvo","BMW","Toyota");
var_dump($cars);
?-->
An object variable is a type of data that holds both the amount of data in the variable and the information needed to process its data.
In PHP, in order to use an object variable, it must be fully and explicitly defined. To do this, we must first define a class for the object. A class is defined by the calss keyword and is a structure that can hold properties and methods related to the object variable.
The following practical example shows how to define a Car class and then create a variable or object from that class called $ herbie. After defining the object variable, it can be used at the program code level:
<!--?php
classCar {
functionCar() {
$this--->model = "VW";
}
}
$herbienewCar();
echo$herbie->model;
?>
Null data is a special variable that can only have one value, empty, empty or Null.
A variable of type Null is a variable to which a value is not assigned.
You can also empty it by assigning a Null value to a variable. Like the following example code:
<!--?php
$x"Hello world!";
$x= null;
var_dump($x);
?-->
Resource-specific data is not really a separate data type. This type of variable actually holds a reference or address to a function, source, or other variable in PHP code.
An example of using a Resource data type is a database call.

Reviews

There are no reviews yet.

Be the first to review “PHP Tutorials”

Your email address will not be published.