Tutorial PHP Variables and how to use them Basic Tutorial

miguel

Administrator
Staff member
Dec 30, 2017
57
1
8
#1
PHP variables allow you to share something across your php code. You can call them wherever so you don't have to be writing the same thing over and over.

How to write a variable in php:

PHP:
<?php
    $myname = "Miguel";
?>
This will let php know that the variable $myname is equal to Miguel.

How to call the variable in your php code:
PHP:
<?php
echo "$myname";
?>
This will print Miguel.

How to mix variable with other content:

PHP:
<?php
$myname = "Miguel";

echo "My name is $myname";

?>
So if you call the variable with any content you should be able print
My name is Miguel.

Any questions please comment below.
 
Last edited:
Forgot your password?
Don't have an account? Register now