PHP Quick Reference Card1
PHP Quick Reference Card1.02
string - single byte character sequence. See below.
__DIR__
Variables that have not been assigned a value or have
been unset contain the special value NULL. A NULL __CLASS__
assignment to an object variable destroys the object.
__METHOD__
Explicit typecasts are rarely needed in PHP. If required Magic constants
use the code
inclusion.
Copyright?, 2008 BrandsPatch LLC
$x = (#)$y; - where # is one of bool, float, int or string.
Operators
Operator
Color key on Page 4
Code Structure
Example
Result
3+ 2
5
.
'Explain'.'That!'
'ExplainThat!'
/ ?*?
3/2
1.5
%
7%4
3
$s = 'Hello from ';
=
$i = 2
$i set to 2
echo $s;
$i = 2;
$i+=1;
3
$site = 'ExplainThat';
function sayHello(){
//single line comment
}
+= ?-=?
s = 'Explain';
function sayHelloEx(){
.=
s.='That!'
'ExplainThat!'
$s = 'Hello from ';
==1
3=='3'
3==3
3==2
true
true
false
global $site;
echo $s.$site;
/*Comment spanning
sayHello();
print $site;
?>
Reusing Code
1 Strings used to identify constants, functions, variables & Heredoc
Purpose
Return Value
empty
Check if empty?
boolean
floatval
Convert to float
float
get_defined_vars List all variables
array
gettype
Verify data type
string1
intval
Convert to int
integer
is_#2
Verify data type
boolean
serialize
Stringify for storage string
settype3
Set data type
boolean
strval
Convert to string
string
unserialize
Regenerate
string
unset4
Destroy the var
from boolean,
integer etc
-
1 array, boolean, integer, double, string or object
2 # is one of array, bool, float, int, null, object, scalar, string
3 second parameter is a string. See note 1 above
4 behavior inside a function depends on nature of variable being unset
false
true
false
!= or
'php'!='PHP'
3!=3
true
false
!==
3!=='3'
true
< ?>?
2
Looping
function whileLoop($num){
while ($num > 0)
{echo($num).'';
$num--;}
}
function doLoop($num){
do{
echo($num).'';
$num--;
}while ($num > 0);
}
function forLoop($num){
for ($i=0;$i
Miscellanea
Warning ¨C thoughtless use of the features described
here could seriously damage your server installation.
The prepend operator, @, can be used with constants,
variables, function calls, eval and include to suppress
error messages.
The backticks operator `returns the results of running a
shell command. For instance, `ls` - dir on Windows ¨C
would return a directory listing. This can be assigned to
a variable or echoed to standard output. Typing 96 while
holding down the ALT key is a keyboard layout
independent way of entering the ` operator.
eval($expr) evaluates the PHP code provided in the
break causes immediate termination of the loop. Loop string $expr. The string must be valid PHP code ¨C
statements after continue are skipped and the next inclusive of terminating semicolons. Errors in $expr may
cause the parser to die. Code in $expr forms part of the
execution of the loop is performed.
parent script so variable assignments in $expr are
function foreachLoopA(){
retained.
foreach($GLOBALS as $key => $value){
PHP in HTML
echo $key.'='.$value.'';
The safest way to embed PHP code in HTML is to
}
delimit it using the tag pair. Other syntax
}
exist but are not accepted by all web servers. The
function foreachLoopB(){
resulting file should be saved with the extension .PHP.
foreach($_SERVER as $value) echo $value.'';
4
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- free excel quick reference sheet
- hospice eligibility quick reference guide
- sba loan quick reference guide
- excel vba quick reference pdf
- excel 2010 quick reference card
- sba quick reference guide 2019
- mla quick reference sheet
- excel 2016 quick reference pdf
- excel quick reference cards 2019
- apa quick reference sheet
- icd 10 quick reference sheets
- icd 10 quick reference list