By Gagandeep Singh Tathgar While working with any language we make use of What is a variable? A PHP Variable Syntax $var_name = value; Defining Variable in PHP? Here is an example of how to declare a variable in PHP. Some key points to notice: - Remember to put the $ sign in front of variables when declaring variables in PHP. - Variable names must start with letters or underscore. - Variables can’t include characters except letters, numbers or underscore. PHP variable types? Unlike //an integer variable //an float variable PHP Variable type juggling Like //string var //var is now float //var is now integer //var is now string ?> Concatenating variables in PHP? In PHP we can join two variables by using the dot '.' operator. $var1 = "I Love PHP"; //prints "I Love PHP and Java" $var1 = "1"; //prints "12"; ?> So there you have it, a quick and easy variable lesson in PHP. You can see more examples of PHP variables at http://php-learn-it.com/php_variables.html or go to Learn PHP for more tutorials. Have fun coding!
variables. Variables are used to store values and reuse them in our
code. We use different types of variables in our code such as strings
(text), integers (numbers), floats (decimal numbers), boolean (true or
false) and objects. In PHP we can make use of variable while writing
scripts. In this lesson we're going to cover PHP variables.
variable is a mean to store values such as strings, integers or
decimals so we can easily reuse those values in our code. For example,
we can store a string value such as "I Love PHP" or an integer value of
100 into a variable.
Java or C++, PHP doesn't care about primitive types. Any variable,
either a string, an integer or a float is declared the same way. PHP
converts the types in the code by itself. Here's what I mean.
$var_name = 100;
$var_name = 100.00
?>
mentioned above, PHP doesn't require variables to declared using
primitive types. Therefore, juggling between two types doesn't require
use of any special function. We can simply do things like...
$var = "0";
$var += 2.5;
$var += 2;
$var .= " is the total";
echo $var;
$var2 = " and Java";
echo $var1 . $var2;
$var2 = "2";
echo $var1 . $var2;
Sunday, June 10, 2007
PHP Web Development: PHP Variables
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment