PHP


Types

string

String

"This is a string!"

int

Integer

64

float

Float (number with decimal point)

64.0

bool

Boolean value (either true or false)

true

array

Array (collection of data that cannot be mutated)

array<(a class=green>"A", 2)

Arithmetic operators

+

Addition

1 + 2

Unary positive, makes number positive

+2

-

Subtraction

2 - 1

Unary negative, makes number negative

-2

*

Multiplication

2 * 3

/

Division

4 / 2

//

Floor division (rounds division down)

4 // 2

%

Modulo (remainder of division)

4 % 2

**

Indice

4 ** 2

Assignment operators

=

Equals

x = 2

+=

a+=b is a=a+b

x += 2

-=

a-=b is a=a-b

x -= 2

*=

a*=b is a=a*b

x *= 2

/=

a/=b is a=a/b

x /= 2

//=

a/=b is a=a//b

x //= 2

%=

a%=b is a=a%b

x %= 2

&=

a&=b is a=a&b

x &= 2

|=

a|=b is a=a|b

x |= 2

^=

a^=b is a=a^b

x ^= 2

>>=

a>>>=b is a=a>>>b

x >>= 2

<<=

a><<=b is a=a><<b

x <<= 2

Comparison operators

==

Is equal to

1 == 2

!=

Is not equal to

1 != 2

<>

Is not equal to

1 <> 2

===

Checks if two objects are equal and of the same type

!==

Checks if two objects aren't equal or are of different types

<=>

The spaceship; in a<=>b, returns 0 if a==b, 1 if a>b, and -1 if a<b

>

Greater than

1 > 2

<

Less than

1 < 2

>=

Greater than or equal to

1 >= 2

<=

Less than or equal to

1 <= 2

and

AND operator

true and false

or

OR operator

true or false

xor

XOR operator

not true

&&

AND operator

true and false

||

OR operator

true or false

!

NOT operator

! true

Identity operators

Miscellaneous operators

.

Concatenates strings

'These are '.'two strings!'

$

Variable operator

,

Used to separate parameters

<?php >

PHP code operator

->

Applies method to object

$instance->method()

Denotes class of an object

math.sqrt(2)

[]

References index of superglobal variables

$_GET["parameter"]

References a array's index

()

Denotes parameters of a function

crypt("Hello world!");

{}

Defines a block

function foo() {
}

;

Declares end of a line of code

:

Used for switch cases

""

Declares a string

"This is a string!"

''

Declares a string

'This is a string!'

*

The splat; indicates unknown amount of arguments for a parameter and treats them as one tuple

def foo(*args):

Key word

echo

Outputs data to screen

echo "data";

function

Declares a function

function foo() {
 code;
}

Used for including a class in another class, creating polymorphism

switch

Used for declaring switch statement

case

Used for declaring case statement in a match statement

if

Executes code if condition is true

if (condition) {
 code;
}

while

Loops code while a condition is true

while (condition) {
 code;
}

do {
 code;
}
while (condition);

for

Loops code for a set amount iterations or for every object in list

for (initialization; condition; update) {
 code;
}

foreach (array as variale) {
 code;
}

foreach

Used for declaring foreach loops

try

Attempts to execute code and jumps to the subsequent catch on an error

try:
code

catch

Executes code on failed try statement

catch (Exception exception) {
 code
}

elseif

Executes code on true condition if the last if statement was false

elseif (condition) {
 code;
}

else

Executes code when if or elif isn't executed

else {
 code;
}

is

Used for testing if two variables are the same

and

Used for applying and logic

or

Used for applying or logic

xor

Used for applying not logic

as

Used for declaring foreign files as a variable

import

Used for importing foreign classes for use in code

return

Used to give a final value at the end of a method

pass

Used to tell compiler to do nothing

continue

Used to tell compiler to complete the next iteration of a loop

break

Used to tell compiler to end the loop

with

Used to handle function with variable for a portion of code

as

Used to handle class or variable with an alias name

raise

Used to throw a specific error

global

Used to declare public variable in a method

true

Used to declare true boolean

false

Used to declare false boolean

this

Used to reference the object of the class

new

Used for declaring new objects from a class

private

Used for declaring private classes or methods, that cannot be interacted with by other classes

public

Used for declaring public classes or methods, that can be interacted with by other classes

do

Used for declaring loop in a while loop

class

Declares a class

class class {
 code;
}

Array functions

array

Declares an array

array_diff

Returns array containing the elements that are not in every array parsed as a parameter

array_push

array_pop

Math functions

sin

cos

tan

sqrt

pi

rand

log

exp

abs

pow

Filesystem functions

file

Reads a file into an array

fclose

fwrite

file_get_contents

Reads a file into a string

rename

scandir

empty

unlink

del

MySQLi functions

MySQLi functions

mysqli

Constructor for a mysqli object

query

Sends a query string to a mysqli object

Networking functions

header

Sends HTTP header to client

setcookie

Sets a cookie

http_status_code

Returns HTTP status code

ip2long

Returns IP as a long

Variable handling functions

isset

Returns a boolean based on whether a string is empty

Argument specifiers

%s

String

%d

Integer

%f

Float

%.1f

Float with 1 decimal place, the 1 can be modified to imply more decimal places

%x

Integer in hexadecimal (lowercase a b c d e f)

%X

Integer in hexadecimal (uppercase A B C D E F)

Escape characters

\a

Bell or alert, has hex code 0x07

\b

Backspace, has hex code 0x08

\cx

Control-X

\C-x

Control-X

\e

Escape, has hex code 0x1b

\f

\M-\C-x

\n

Newline, has hex code 0x0a

\nnn

\r

\s

Space, has hex code 0x20

\t

Space, has hex code 0x20

\v

Vertical tab, has hex code 0x0b

\x

\xnn

Directives

import

Includes foreign file's class

import module

Superglobal Variables

$_GET

References a GET parameter

$_GET["parameterName"]

$_POST

References a GET parameter

$_SERVER

References server-side information and header information

Wrappers

php

data

expect

http

Wrapper for accessing resource over HTTP

https

Wrapper for accessing resource over HTTPS

ftp

Wrapper for accessing resource over FTP

phar

Executes a phar archive

zip

Wrapper for acessing file within a compressed folder

import

Includes foreign file's class

import module

Commenting

#

Used to tell compiler the rest of this line is not to be compiled

#This isn't executed