PHP Variables

Rules for PHP variables:

  • A variable starts with the $ sign, followed by the name of the variable
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($age and $AGE are two different variables)

PHP supports the following data types:

  • String
  • Integer
  • Float (floating point numbers – also called double)
  • Boolean
  • Array
  • Object
  • NULL
  • Resource

To get the data type of a variable, use the var_dump() function or use the echco gettype() function.

var_dump($name);
echo gettype($name);

Variable can assign in between double cotation.

Change Data Type- $num=(string)$age;


echo can have multiple parameters.

echo" First Name ", $fname; //echo can have multiple parameters.

echo ” First Name.$fname”; // dot sign is as concatenation
echo ” First Name $fname”;

$name=”seelan”;
$$name=”yohga”;

echo $name; //seelan
echo $seelan; //yohga
echo $$name; //yohga

Categories: ,

Leave a Reply

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

Related Posts :-

  • PHP-2

    PHP Variables Rules for PHP variables: PHP supports the following…

  • PHP-1

    What is PHP? PHP (Hypertext Preprocessor) is a server-side scripting…

  • Java OOP-1

    Class Object Blueprint / Template(Plan) Real world entry can’t visual…