What is php? Define variables and Datatypes how to use it?

In this tutorial i’m going to explore about what is PHP and their datatypes and how to use of variables.
PHP is a open-source side programming language that is specially suited for web development and can be embeded to HTML. It is powerful to hold a content management system like WordPress and can be used to control user access. PHP can actually do anything related to server-side scripting or more popularly known as the backend of a website, it is more secure and reliable to be used as a server-side scripting language.

What is DataTypes?

Datatypes is a range of all different data can be given variable in PHP. It’s supports these string.

  1. String
  2. Integer
  3. Float (floating point numbers – also called double)
  4. Boolean
  5. Array
  6. Object
  7. NULL
  8. Resource

How to write datatypes in PHP?

  1. string:- string is a data type used in programming, string is a sequence of character its supports a 256-character. The simplest way to create a string is to enclose the string literal (i.e. string characters) in single quotation marks (‘), like this:

    $my_string = ‘Hello World’;

2. Integer:- An integer is a number without any decimal part.

<?php  
    $x=123;  
    echo $x;  
?>  

3. Float:- A float is a number with a decimal point as like- 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats

4. Boolean:- A boolean data can be either TRUE or FALSE. These are predefined constants in PHP.

var_dump((bool) -2);        // bool(true)
var_dump((bool) "foo");     // bool(true)
var_dump((bool) 2.3e5);     // bool(true)
var_dump((bool) array(12)); // bool(true)
var_dump((bool) array());   // bool(false)
var_dump((bool) "false");   // bool(true)


5. array:- An array stores multiple values in one single variable.

<?php
$cars = array(“Volvo”,”BMW”,”Toyota”);
var_dump($cars);
?>

6. Object:- Objects are the instances of user-defined classes that can store both values and functions. They must be explicitly declared.

7. Null:- Null is a special data type which can have only one value Null, if variable is created without a value it is automatically assigned a value of Null.

8. Resource:- Resources are not the exact data type in PHP. Resource is the storing the refrenece to functions call or refrences to external PHP resource as like database.

Tagged : / / /