$type=carousel$cols=3$cate=0$date=1

Declaring Variable in PHP

In PHP a variable is represented with a $ sign and followed by the name of the variable. A variable name must start with a letter or the ...

In PHP a variable is represented with a $ sign and followed by the name of the variable. A variable name must start with a letter or the underscore character but cannot begin with a number. Variable name is case-sensitive. So $name, $Name, and $NAME are three different variables. A variable can have a short name ie x and y. When assigning a text value to a vairable, two double quotes are used to the value that has been assigned. A variable name can only contain alpha-numeric characters and underscores A-z, 0-9, and _ . The following example will show how to output a variable:

A variable can store a string or a number.

All variable names in PHP should start with a dollar sign ( $ ).

And to end the statement PHP requires a semicolons.

Note : No quotes should be used around numbers.

Example :

$myCountry = "INDIA";
$countryCode = 91;

Let's get started by creating a variable and giving it a value.

Now, Declare a variable, $myCountry, and give it your Country name as a string.

    <html>
    <body>
    <?php
    $myCountry = "INDIA";
    echo "$myCountry";
    ?>  
    </body>
    </html>
 
    Use echo to print out your country name

More Example of Variables :

    <html>
    <body>
    <?php
    $text = "Example";
    echo "Displaying temperature using " . $text . "!";
    ?>
     <br /> <br />  
 
    <?php
    $v_temp = 30.2;
    echo "$v_temp &deg;C";
    ?>
    <br /><br />

    <?php
    $name = "Iwriteless";
    echo $name;
    ?>
    </body>
    </html>

A variable is declared using the = operator, and the variable on the left side and the name of the variable to right side. To end the statement add a semicolon (;) Simply echo the variable name to output data to the screen. Now save the file as .php and HIT SAVE.


END...

COMMENTS

Name

css,17,html,7,php,2,python,1,tech,18,
ltr
item
iWriteLess Tech Blog: Declaring Variable in PHP
Declaring Variable in PHP
iWriteLess Tech Blog
http://www.iwriteless.com/2016/01/declaring-variable-in-php.html
http://www.iwriteless.com/
http://www.iwriteless.com/
http://www.iwriteless.com/2016/01/declaring-variable-in-php.html
true
2724151228810149585
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy