Complete PHP Reference's
Intro Of PHP?
PHP (Hypertext Preprocessor) is a popular server-side scripting language used primarily for web development. It is embedded within HTML and interacts with databases, handles forms, manages sessions, and builds dynamic websites.
📌 1. PHP Opening & Closing Tags
| Tag | Description |
| <?php ... ?> | Standard PHP opening and closing tags |
| <?= ... ?> | Short tag for echoing |
| <script language="php"> ... </script> | Not recommended (old-style PHP tag) |
📌 2. PHP Data Types
| Type | Description |
| int | Integer values |
| float (or double) | Decimal numbers |
| string | Text |
| bool | Boolean (true/false) |
| array | Array of values |
| object | Instance of a class |
| null | Represents no value |
| resource | Special resource type (e.g., file, DB connection) |
📌 3. PHP Keywords
| Keyword | Description |
| echo | Output text |
| print | Output text (returns 1) |
| if | Conditional statement |
| else | Alternate block for if |
| elseif | Else-if conditional |
| switch | Switch-case logic |
| case | Used inside switch |
| default | Default case in switch |
| while | Looping construct |
| do | Do-while loop |
| for | For loop |
| foreach | Loop for arrays |
| function | Define a function |
| return | Return from a function |
| global | Access global scope |
| static | Preserve variable state |
| var | Old way to declare variables |
| public | Public class member |
| private | Private class member |
| protected | Protected class member |
| class | Declare a class |
| interface | Declare interface |
| extends | Inheritance |
| implements | Implement interface |
| const | Declare constant |
| define() | Define constant function |
| include | Include file |
| require | Require file (fatal error if missing) |
| include_once | Include only once |
| require_once | Require only once |
| try | Try block for exception |
| catch | Catch block |
| finally | Always executed block |
| throw | Throw an exception |
| new | Create object |
| clone | Clone object |
| instanceof | Check object type |
| unset | Remove variable |
| isset | Check if set |
| empty | Check if empty |
| die / exit | Terminate script |
| declare | Set execution directives |
| yield | Return a value from a generator |
📌 4. Common Superglobals
| Superglobal | Purpose |
| $_GET | Access query string data |
| $_POST | Access form data (POST) |
| $_REQUEST | Access both GET and POST |
| $_SERVER | Server info |
| $_SESSION | Session variables |
| $_COOKIE | Cookie data |
| $_FILES | File upload data |
| $_ENV | Environment variables |
| $GLOBALS | Access all global variables |
📌 5. PHP Common Functions
| Function | Purpose |
| strlen() | Get string length |
| str_replace() | Replace string |
| substr() | Get part of string |
| array_push() | Add item to array |
| array_merge() | Merge arrays |
| explode() | Split string into array |
| implode() | Join array into string |
| isset() | Check if variable is set |
| empty() | Check if variable is empty |
| is_array() | Check if array |
| is_string() | Check if string |
| file_get_contents() | Read file to string |
| file_put_contents() | Write string to file |
| header() | Send raw HTTP headers |
| date() | Format date/time |
| time() | Unix timestamp |
| json_encode() | Convert to JSON |
| json_decode() | Convert from JSON |
Click to go back on notes page.