More Reference Sheets & Get Programming Help @: Edited By: Hotsnoj, Martyr2 Published: October 18, 2007
The document provides an overview of common data types, variables, operators, and structures used in PHP including arrays, loops, functions, classes, sessions, and error handling. It defines syntax for variable declarations, arrays, comments, arithmetic/logical/assignment operators, if/else statements, loops, strings, and more.
More Reference Sheets & Get Programming Help @: Edited By: Hotsnoj, Martyr2 Published: October 18, 2007
The document provides an overview of common data types, variables, operators, and structures used in PHP including arrays, loops, functions, classes, sessions, and error handling. It defines syntax for variable declarations, arrays, comments, arithmetic/logical/assignment operators, if/else statements, loops, strings, and more.
integer, float, boolean, string, array, object, resource, NULL $GLOBALS (Access all global variables in script) $_SERVER (Access web server variables) Variable Declarations $_GET (Values passed to script through URL) $variablename = <value>; $_POST (Values passed to script through HTTP Post) $anothervariable =& $variablename; (Assign by Reference) $_COOKIE (Values passed by user cookie) $_FILES (Values ( passed by HTTP Post File Uploads) Declare Array $_ENV (Values passed to script via the environment) $arrayname = array(); $_REQUEST (Values passed by URL, HTTP Post, or user Cookies) $_SESSION (Values passed through user's session) Initialize Array $arrayname = array(<value1>, <value2>, <value3>); If Else $arrayname = array(<key> => <value>, <key> => <value>); (Define Keys) if (<condition 1>) $multiarray = array(<key> => array(<value1>,<value2>)); (Multi-dimensional) { <statement 1>; } elseif (<condition 2>) Common Array Functions { <statement 2>; } sort(<array>); (Sort array assigns new keys) else asort(<array>); (Sort array maintain keys) { <statement 3>; } rsort(<array>); (Sort array in reverse, new keys) arsort(<array>); (Sort array in reverse, maintain keys) Inline If (Ternary) count(<array>); (Count elements) <condition> ? true : false; count(<array>,COUNT_RECURSIVE); (Count multidimensional array) array_push(<array>,<value>); (Push item onto end of array) For Loop array_pop(<array>); (Pop item off end of array) for (<initialize>;<condition>;<update>) { Comments <statements>; // Comment text } /* Multi-line comment text */ # Comment text For Each Loop foreach (<array> as [<value> |<key> => <value>]) Arithmetic Operators { + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus) <statements>; [break]; Relational Operators [continue]; == (Equal), === (Equal with type comparison), != (Not equal), <> (Not equal), !== (Not Equal } with type comparison), < (Less than), > (Greater than), <= (Less than or equal to), >= (Greater than or equal to) While Loop while (<condition>) Logical Operators { ! (logical NOT), && (logical AND), || (logical OR), xor (logical XOR) <statements>; } Assignment Operators = (Assign), += (Addition), -= (Subtraction), *= (Multiplication), /= (Division), .= Do-While Loop (Concatenation), %= (Modulus), &= (And), |= (Or), ^= (Exclusive Or), <<= (Left Shift), >>= do (Right Shift) { <statements>; String Concatenation } while (<condition>); . (Period) Switch String Manipulation switch (<expression>) substr(<string>,<start>,[<length>]); { strlen(<string>); case <literal or type>: trim(<string>); <statements>; ltrim(<string>); // Trim left [break;] rtrim(<string>); // Trim right case <literal or type>: strtolower(<string>); <statements>; strtoupper(<string>); [break;] str_replace(<search>,<replace>,<string>,[<count>]); default: strpos(<string>, <search>); <statements>; strcmp(<string1>,<string2>); (Binary safe string comparison) } strcasecmp(<string1>,<string2>); (Binary safe case-insensitive comparison) explode(<delim>,<string>,[<limit>]); (Break string into array) Function Structure implode(<delim>,<array>); (Join array into string separated by delim) function <function_name>([<parameters>]) { Cookies <statements>; setcookie (<cookiename>, [<value>],[<expire_time_in_secs_since_epoch>]); [return <value>;] $_COOKIE['cookiename']; (Returns value of cookie) }
Sessions Class Structure
session_start(); (Create session) class <class_name> [<extends base_class>] $_SESSION['key_name'] = value; (Set session variable) { $variablename = $_SESSION['key_name']; (Retrieve value from session variable) [var | <modifiers*>] [<class member variables>]; session_destroy(); (Destroy session) [<modifiers*>] function <function_name>([<parameters>]) { Error Handling <statements>; try { } <statements that may cause error>; } } catch (<Exception Class> $exception_name) * Modifiers <public | pr ivate | static> are implemented in PHP5 { <statements to execute when error is caught>; Declare and Use Class } $variable = new class_name(); $variable->function_name(); class_name::function_name(); (Static call)
Download More Reference Sheets & Get Programming Help @
http://www.DreamInCode.net Edited By: hotsnoj, Martyr2 Published: October 18, 2007