Logo

Codcups

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

TagDescription
<?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

TypeDescription
intInteger values
float (or double)Decimal numbers
stringText
boolBoolean (true/false)
arrayArray of values
objectInstance of a class
nullRepresents no value
resourceSpecial resource type (e.g., file, DB connection)

📌 3. PHP Keywords

KeywordDescription
echoOutput text
printOutput text (returns 1)
ifConditional statement
elseAlternate block for if
elseifElse-if conditional
switchSwitch-case logic
caseUsed inside switch
defaultDefault case in switch
whileLooping construct
doDo-while loop
forFor loop
foreachLoop for arrays
functionDefine a function
returnReturn from a function
globalAccess global scope
staticPreserve variable state
varOld way to declare variables
publicPublic class member
privatePrivate class member
protectedProtected class member
classDeclare a class
interfaceDeclare interface
extendsInheritance
implementsImplement interface
constDeclare constant
define()Define constant function
includeInclude file
requireRequire file (fatal error if missing)
include_onceInclude only once
require_onceRequire only once
tryTry block for exception
catchCatch block
finallyAlways executed block
throwThrow an exception
newCreate object
cloneClone object
instanceofCheck object type
unsetRemove variable
issetCheck if set
emptyCheck if empty
die / exitTerminate script
declareSet execution directives
yieldReturn a value from a generator

📌 4. Common Superglobals

SuperglobalPurpose
$_GETAccess query string data
$_POSTAccess form data (POST)
$_REQUESTAccess both GET and POST
$_SERVERServer info
$_SESSIONSession variables
$_COOKIECookie data
$_FILESFile upload data
$_ENVEnvironment variables
$GLOBALSAccess all global variables

📌 5. PHP Common Functions

FunctionPurpose
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.