Articles added in Mathematics Lab | Cyber Lab is now open | Astronomy Lab is now open | VLSI Lab is now open | 120 SEO Tips article published | More exciting articles coming soon!




PHP Variables

Variables in PHP

  • All variables in PHP are preceded by a $ sign.

  • Value of the variable is the most recent value assigned to it.

  • It is not compulsory to declare a variable before using it, these act as unassigned variables.

  • Variables can be composed of numbers (0-9), letters (A-Z, irrespective of their case), and underscore (_)characters.

  • E.g.: $pi, $capital, etc.

    NOTE: The first character cannot be a number.

    A variable is created as soon as a value is assigned to it. The syntax for assigning a value is: $pi=3.14;
    $pi=3+0.14;

    Here, the expression 3+0.14 is evaluated and the value is assigned to pi.
    If you want to assign a string to the variable you can quote the expression as: $pi="3+0.14", here the value of pi is the string 3+0.14.

    No data types have to be declared for a variable in php. PHP figures out the type of expression declared. PHP also does automatic type conversion.

    E.g. : $sum=2+0.5;
    Here, sum will automatically have a floating point number.

    NOTE: Singly quoted strings read in and store their value literally.

    E.g.: $s='hello\n'; print"$s";
    o/p: hello\n
    To embed (') in a singly quoted string use a backslash preceding it (\') to escape it.

    NOTE: There are multiple escape sequences like \n, \t, \', \\, \", \$, etc.






    CACKLE comment system





    Programming Resources
    Computer Networking Fundamentals Android Application