You are here: Daniel Dumas » Blog, PHP »

PHP and MySQL Basics: Assigning and Using Variables

PHP and MySQL Basics: Assigning and Using Variables

Assigning a value to PHP variable is very easy, you can use the assignment operator ( = ) to store values into a php variable. refer below for example.

<html>
<head>
<title>Assigning Values to PHP Variable</title>
</head>
<body>
<?php
//this is how you assign a value to a php variable
$age = 20;
//To use the variable $age, simply call its name and PHP will substitute its value at runtime.
//this is how you use a php variable
echo "I am now $age years old";
?>
</body>
</html>

copy and paste the code above to your text editor and save it as variable.php then run it on your localhost.

you should get this output..

assigning values to php variables

Discussion

  1. Wow..Ang galing, ganda ng theme mo bro! ;)

  2. I guess it could help someone get started… Maybe you could take it a little further and explain how to get them from $_GET, and also how to concatenate using .= and maybe even some +=, ++ action.

    =)

    • Daniel Dumas says:

      yeah we’ll get into that hehe this section is just an introduction on how to assign and use php variables for a total beginner, i have a section for php global variables. i will compile this tutorial into one page when i finished this. .thanks for comment hehe

Leave a Reply





Spam protection by WP Captcha-Free