Variable

$variable = “”;

String

“a string”

to escape a character means to preface it with a backslash

That\’ll do it

output a variable

echo “$variable”

Array

The array in PHP are not confined to one data type per array.

$array_variable = array(“item1”,”item2",”item3",”item4");

Associative arrays

$person = array(
“name” => “demo”,
“other” => “false”,
“insert” => array(“”,””)
);

Access it

$array[4] = “”;
$array[“string”] = “”;

Comments

# this is a comment
// this is a comment
/*
multiline line
comments
*/

Operator

Arithmetic Operator

$variable = $variable + 10;
$variable = $variable — 5;
$variable = $variable / 5;
$variable = $variable * 2;
5 % 3 ; //2 This is modulus;

Assignment Operator

$variable += 10;
$variable -+ 10;
$variable /= 10;
$variable *= 10;

Others

Incrementing ,Decrementing Operator,Comparison Operator,

The Same behavior as C++ and most language

Falsy value

  1. “”(empty string)
  2. 0
  3. false
  4. null
  5. array()(an empty string)

Conditional Operator

conditional ? if_true : if_false;

Function

Here is the syntax:

function functionName ($param) { 
return “”;
}

For loop

If we want to output a list

$array = ….;
echo “<ul>”;
for ($i = 0; $i < count($array); $i++){
echo “”;
}
echo “</ul>”

or we can save the value in a variable so we just call count() once

for ($i = 0,$length = count($array);$i < $length; $i++)

loop over associative array

echo “<ul>” 
foreach($array as $value) {
echo “<li>$value</li>”
}
echo “</ul>”

OR

foreach($array as $key => $value){ 
echo “$key and $value”;
}

switch case

switch ($variable) { 
case “someValue”:
echo “”;
break;
case “anotherValue” :
echo “”;
break;
}

require/include/require_once/include_once

the difference between include and require happens when the file cannot be found. If include can’t find the file,it will output a warning.and continue going on.If require can’t find the file.it will issue a fatal error and it stops executing the following code.

the difference between include_once and require_once is if the file has been included or required in the file,they won’t bring it in again.