Friday, 1 September 2017

PHP | Variable in PHP | Rules for define PHP variables - W3Tricks

Variable in PHP | Rules for define PHP variables


What is Variable and what it Work?

  • Variables are "containers" for storing( Hold ) information( Data ).

Rules for define PHP variables

  • A variable name must start with a letter ( A - Z and a - z ) or the underscore Symbol ( _ ).
  • A variable name cannot start with a number ( 1 to 0).
  • A variable name can only contain alphanumeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($Data and $data are two different variables).

Program

<?php

$1data; // not valid start with number
$123;   // not valid start with number
$*data //  not valid start with Symbol

$data; // it is valid
$_data; // it is valid
$_123; // it is valid


$data;
$Data;

/* both are different Variables */

?>

Note:

  • When you assign a text value to a variable ( $string = "IT is String"; ) put quotes around the value.
  • Unlike other programming languages PHP is loosely typed language, PHP has no command for declaring a variable.
  • It is created the moment you first assign a value to it.
  • 1. $int = 132; // It is integer 2. $str = "String"; // It is String

0 comments:

Post a Comment