List Of Syntax Used In PHP!
Here's a cheat sheet to add to the collection of PHP programmers, happy coding!
Our previous articles with List Of Syntax Used In Python and Mathematica received warm response
from the readers. While some loved and appreciated the articles, quite a few asked for similar list on
PHP. Hence, on popular demand, we bring to you a cheat sheet on syntax used in PHP.
Language Category: Object Oriented, Dynamically typed
Various
block (grouping statements, especially when statements are
{ ... }
not expressions)
breaking lines (useful when end-of-line and/or indentation has
nothing needed
a special meaning)
/* ... */
commenting (non nestable)
#
commenting (until end of line)
//
commenting (until end of line)
< > <= >=
comparison
strcmp
comparison (returns 3 values (i.e. inferior, equal or superior))
/** ... */(1)
documentation comment (non nestable)
Err:510
equality / inequality (shallow)
( ... )
grouping expressions
__LINE__ __FILE__
information about the current line and file
eval
runtime evaluation
case-sensitive: variables
case-insensitive: keywords, functions, tokens (case-sensitivity (keywords, variable identifiers...))
constants...
[_a-zA-Z][_a-zA-Z0-9]*
tokens (variable identifier regexp)
=
variable assignment or declaration (assignment)
Functions
create_function(',','...')
anonymous function
f(a,b,...)
function call
f()
function call (with no parameter)
Return(3)
function return value (breaks the control flow)
Control Flow
continue / break
breaking control flow (continue / break)
Return(3)
breaking control flow (returning a value)
if (c) ...
if_then
if (c): ... endif
if_then
if (c) b1 elseif (c2) b2 else b3
if_then_else
if (c): b1 elseif (c2): b2 else: b3 endif
if_then_else
c ? b1 : b2
for
for ($i = 1; $i <= 10; $i--) ...
if_then_else
loop (for "a la C" (while + initialisation))
loop (for each value in a numeric range, 1 decrement)
loop (for each value in a numeric range, 1 increment (see also
the entries about ranges))
loop (for each value in a numeric range, free increment)
loop (while condition do something)
for ($i = 1; $i <= 10; $i++) ...
for ($i = 1; $i <= 10; $i += 2) ...
while (c) ...
switch (val) {
case v1: ...; break;
case v2: case v3: ...; break;
default: ...;
}
multiple selection (switch)