PHP Code block and Variables

PHP is influenced by C languages, just like JavaScript. We won’t go into detail since we’ve I assumed that you’ve learnt JavaScript in the early chapter of this book, therefore I will focus more on areas that are not synonymous with JavaScript.

First, PHP statement or code must reside with the within the PHP; start <?php and end ?> block as you have seen in the last example.

<?php .... ?>


Secondly, PHP variable must start with a dollar sign $, for example $LastName while all other rules in the JavaScript chapter are all applicable too for naming the Variable.

Finally PHP is loosely typed language, that is, it determine the data type of a variable at run time when you request the PHP page or function, this is a feature that languages like C, C++, Java, C# and  others, strongly discourage, as they insist you must declare every variable before usage, hence they are called strongly typed language. This PHP feature has it advantage and disadvantage, but just as I said earlier Rasmus Lerdorf (creator of PHP) must have taught that most web developer or programmers are also busy with other things therefore saving them from this hustle of declaring all variable with type before usage, we will see the next example Form processing using PHP what I mean.
.

Although the variable described above is what most people refer to as variable but PHP also other kinds of built-in variable for different types of operation, see the list below

$_POST: holds variables provided through the form POST method
$_GET: holds variables provided through the POST method
$_SESSION: holds any variables that are currently registered in a session
$_SERVER: holds server related information such as headers and file paths
$_FILES: holds any variables provided through file uploads.
$_ENV: handles server environment related variables.


Although PHP has more than this unique variables, but these are the ones we are likely going to be using in the book, most especially the first two or three, this is because the $_POST is often use to collect data from form with POST method, and this is where web application becomes very handy, See the next topic form processing for more. 

 

VERY IMPORTANT
Please note that many basic programming topics like variables, operators, Decision (conditional statements) and Looping have already being discussed in our Javascript tutorial, instead of repeating this topics, I will advise you please go and read this material in our Javascript tutorial as they are equally applicable to PHP.

 

Next »


Introduction to PHP and MySQL »

Setup PHP and MySQL »

Starting WAMP Server »

Testing the WAMPServer (First PHP Program) »

PHP Code block and Variables »

Form processing using PHP »

Sending e-mail with PHP »

PHP Interaction with a Database »

SAMPLE1: a Feedback system »

SAMPLE2: Authentication system »

More PHP sample code »