user41752
0
Q:

php $$ variable

<?php
    //can also use print instead of echo and would return  but it is
    //slower so use echo mainly
    #variable rules
    /*
        - Prefix with a dollar sign $
        - Start with a letter or an underscore only
        - Only letters, numbers and underscores
        - Case sensative
    */

    #DATA TYPES
    /*
        Strings
        Integers 4
        floats 4.4
        Booleans True or Flase
        Arrays
        Objects
        Null
        Resources 
    */
    $output = '  Hello there Bob!!';
    $num1 = 4;
    $num2 =10;
    $sum = $num1 + $num2;
    $string1 = '  Hello';
    $string2 = 'Bobby!!';
    $greeting = $string1 .' '. $string2;
    $greeting2 = "$string1 $string2";

    $string3 = ' They\'re Here';

    #making a constant

    define('GREETING', ' Hello Everyone!!');

    echo $sum;
    echo $output;
    echo $greeting;
    echo $greeting2;
    echo $string3;
    echo GREETING;
?>
5
$name = "Josh"; //$varname = value
0
Input :  $Hello = "Geeks for Geeks"
         $var = "Hello"
         echo $var
         echo $$var
Output : Hello
         Geeks for Geeks

Input :  $GFG = "Welcome to GeeksforGeeks"
         $var = "GFG"
         echo $var
         echo $$var
Output : GFG
         Welcome to GeeksforGeeks
0

New to Communities?

Join the community