PHP Variables


A variable is a name given to a memory area that stores information at runtime.
All factors in PHP are signified with a main dollar sign ($).
Variable names are case touchy; this implies $my_code is unique in relation to $MY_CODE
All factors names must beginning with a letter follow different characters.

PHP has a total of eight data types

1) Integers

They are whole numbers, without a decimal point, like 813.

    echo PHP_INT_MAX;

2) Doubles

Integer can be in decimal (base 10), octal (base 8), and hexadecimal (base 16) format.

   $a = 5.20;
   $b = 5.10;
   $c = $a + $b;
   print("$a + $b = $c 
"); ?>
    5.2 + 5.1 = 10.3 

3) Boolean

They have only two possible values either TRUE or FALSE.

if (TRUE)
   print("This will always print");
   print("This will never print");

4) Strings

A string is a collection of characters. String is one of the data types supported by PHP.

    var_dump('welcome to the dcodeck world');
    string(28) "welcome to the dcodeck world"

5) Array

Arrays are named and indexed collections of other values.

$code = array("html", "css", "js"); 
echo "I love " . $code[0] . ", " . $code[1] . " and " . $code[2] . ".";
    I love html, css and js. 

6) Objects

Objects are occurrences of developer characterized classes, which can bundle up both different sorts of value and functions that are explicit to the class.

class Dpk {
    function Dpk() {
        $this->text = "Coder";
// create an object
$rwt = new Dpk();

// show object properties
echo $rwt->text;

7) Null

NULL is an extraordinary information type which can have just one worth: NULL OR Invalid.
A variable of information type NULL is a variable that has no worth appointed to it.
If a variable is created without a value it is automatically assigned a value of NULL.
Factors can likewise be discharged by setting the incentive to NULL:

$x = "Hello coder!";
$x = null;

8) Resources

Resources are special variables that hold references to resources external to PHP (such as database connections).