PHP was created in 1995 by Rasmus Lerdorf to keep track of his Personal Home Page. It was updated in 1997 by Andi Gutmans and Zeev Suraski as a total rewrite of the original, now aimed towards e-commerce applications. The new version of PHP stands for PHP Hypertext Preprocessor. PHP is an open-source document, so it is constantly being updated and improved. It is a slight transition from JavaScript as PHP is server side scripting, but most of the previously learned programming constructs are the same.

JavaScript to PHP
JavaScriptPHP
Script Tags <script>...</script> <?php ... ?>
Variables var x=0; $x=0;
Concatenation "Hello, "+name; "Hello, ".$name; OR "Hello, $name";
Output document.write("hello"); echo "hello";
if...else if(condition)
&tab;code
else
&tab;code
no change
for loop for(var x=0; x<5; x++) for($x=0; $x<5; $x++)
while while(x<5) while($x<5)
String length myString.length() strlen($myString)
Comments //single line
/* block */
no change
Processing Client Side Server Side
Casting parseInt(myAge) (int)$myAge
Random Numbers parseInt(Math.radom()*(high-low)+low); srand((double)microtime()*1000000;
rand(min, max);
Arrays shift(), unhift(), pop(), push(), splice() array_shift(), array_unshift(), array_pop(), array_push()
Methods function(parameter){
code;
return;
}
no change

Helpful Hints

Working with Arrays

The Math Class

Unlike JavaScript, the use of the Math class name in front is not necessary.
Working with Strings

Unlike JavaScript, string method are not called from objects, but as class methods and take string variables as parameters
Dates

PHP can access the server clock to determine the date and time.   The first step is to call the date() method that takes a string $format and returns a formatted date/time.  There is an optional second parameter that allows the caller to choose the time to be formatted.  Lack of that parameter will format the current time.