Checked At:01:47
3 Guests
0 Users
Online doing the past 15 Minutes!
brugbart.com - Edition/Last Updated: 13. October 2008
Posted The: 11/05/2008 - AT: 14:43
Variables in php begins with a dollar sign, and must be followed either by an underscore or a letter.
Variables refer to a specific memory location, so that information stored can be easily accessed and manipulated later.
You should use variables when you want to save information temporarily for later use.
The below example outputs "My name is BlueBoden" in two different ways, both uses the information we stored in the variable $MyName.
<?php $MyName = 'BlueBoden'; echo 'My name is ' . $MyName; // Using String Concatenation echo "My name is $MyName"; // Using Double Quotes ?>
Storing something in a variable, will allow you to use the variable throughout the script, if you want to store the information for longer then that, you may want to consider using a database, or session variables.
The data types of your Variables is automatically determined doing execution of your script, therefor you don't need to worry about this. However it is a good idea to read up on it, as in languages like c/c++ asigning data types is done manually.
The Integer Type contain number values, while the Double Type contain floating point values, see below:
<?php $Num = 100; // Integer $FloatingNum = 99.5; // Double ?>
Is used to contain textual information like:
<?php $MyName = 'BlueBoden'; // Only letters $WhoIs = 'BlueBoden the 1th'; // A combination of letters and numbers ?>
Is used to easily store many values, in a single variable. This can be done the following ways:
<?php
$UserInformation[0] = 'BlueBoden';
$UserInformation[1] = 'The 1th';
$UserInformation[2] = 'Active:Admin';
// The above can also be set the following way.
$UserInformation = array('BlueBoden','The 1th','Admin');
// The key value dosn't need to be a number, we can also use a string like below.
$UserInformation['Name'] = 'BlueBoden';
$UserInformation['UserCount'] = 'The 1th';
$UserInformation['Status'] = 'Active:Admin';
?>Arrays might seam complex at first, but they should be easy to work with, knowing the above.
Another aspect of strings is refeared to as "String Concatenation", this allow you to connect multiple strings, and variables using the "." dot operator.
<?php $MyName = 'BlueBoden'; $MyString = 'My name is: ' . $MyName; // With multiple variables $MyName = 'BlueBoden'; $UserStatus 'Active:Admin'; $MyString = 'My name is: '; echo $MyString . $MyName . "\n" . 'UserStatus: ' . $UserStatus; ?>
Get the syntax right, and you can enter in just about anything, just like you would in your own language.
The "\n" is just a simple linebreak, the reason i used Double Quotes around it, was to make it apear as a linebreak in the final document; had i simply used Single Quotes, it would apear as the characters "\n" instead of the desired linebreak.
Author: BlueBoden
Comments: [0]


Checked At:01:47
3 Guests
0 Users
Online doing the past 15 Minutes!
This page was created in 0.0728368759155 seconds
Welcome Guest