Categories: Blog

0.05a PHP Variables

Variables are essential to writing code in PHP.

Variables always start with the dollar sign followed by the variable name:
$today = “Friday, April 11 2025”; // this is a string variable
$price = 023.04; // this is a float (floating point number)
$quantity = 12; // this is an integer
$taxable = true; // this is a boolean
Rules for PHP variables:
1. A variable starts with the $ sign, followed by the name of the variable
2. A variable name must start with a letter or the underscore character
3. A variable name cannot start with a number
4. A variable name can only contain alpha-numeric characters and underscores
5. Variable names are case-sensitive ($age and $AGE are two different variables)

Arrays: an Array can be defined like this:
$myarray=array(‘Value1′,’Value2′,’Value3’); // $myarray contains 3 strings
Adding to an array is done like this:
$myarray[]=”John Jones”; // $myarray contains 4 strings
$myarray[]=”Mary Smith”; // $myarray contains 5 strings

Now $myarray contains 5 entries.

They can also be defined like this:
$myarray=array(); // produces an empty array

The PHP superglobal variables are:

1 $GLOBALS
2 $_SERVER
3 $_REQUEST
4 $_POST
5 $_GET
6 $_FILES
7 $_ENV
8 $_COOKIE
9 $_SESSION

more info

Editor

View Comments

Share
Published by
Editor

Recent Posts

0.06a History of MariaDB

Origins 2008 – The Fork Begins MySQL AB had been acquired by Sun Microsystems in…

3 days ago

0.05b PHP Functions

Useful functions built into PHP You can display the entries in an array with the…

3 days ago

1.03 Set up WampServer

WampServer, a Windows web development environment. This only runs on Windows computers but it is…

4 days ago

1.02 Set up XAMPP

XAMPP a local environment for web development. Setting up XAMPP (which stands for X (Cross-Platform),…

4 days ago

1.01 Starting out in PHP

This will get you started writing in PHP. Just go to w3schools.com and click on…

4 days ago

0.06 The History of MySQL

MySQL was created in 1994 by Swedish developers David Axmark and Allan Larsson, along with…

5 days ago