Fundamentals of PHP
|
Files start with
|
<?php
|
|
Single line comment
|
// a comment
|
|
Multi-line comment
|
/ comment /
|
|
End of instruction
|
;
|
|
Include code from another file
|
require_once('some_file.php');
|
|
$variableName;
|
|
$variableName = "Some String";
|
|
$variableName = 'Some String';
|
|
$variableName = strtoupper('text');
|
|
$variableName = 5;
|
|
$variable = "Some {$otherVariable} info";
|
|
echo $variableName; // output
|
|
$newVar = $var1 . $var2; // concatenation
|
|
Addition
|
$variable = $variable + 5;
|
|
Subtraction
|
$variable = $variable - 5;
|
|
Multiplication
|
$variable = $variable * 5;
|
|
Division
|
$variable = $variable / 5;
|
|
Create
|
$myArray = array();
|
|
Push into
|
$myArray[] = "Something";
|
|
Push to associative
|
$myArray['key'] = "Value";
|
|
Create numeric
|
$myArray = array('value', 'value2');
|
|
Create associative
|
$a = array('key'=>'val');
|
|
Print from numeric
|
echo $myArray[0];
|
|
Print from associative
|
echo $myArray['key'];
|
|
Associative arrays
|
Keys are strings
|
|
Numeric arrays
|
Keys are numbers: 0,1,2,3,4
|
There is a mistake in multiline comment. Should be /* */
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.