PHP

PHP: indicates the earliest version of PHP that supports the function.

PHP String Constants

PHP: indicates the earliest version of PHP that supports the constant.

Constant

Description

PHPCRYPT_SALT_LENGTH

Contains the length of the default encryption method for the

system. For standard DES encryption, the length is 2

CRYPT_STD_DES

Set to 1 if the standard DES-based encryption with a 2 character salt is supported, 0 otherwise

CRYPT_EXT_DES

Set to 1 if the extended DES-based encryption with a 9 character salt is supported, 0 otherwise

CRYPT_MD5

Set to 1 if the MD5 encryption with a 12 character salt starting with $1$ is supported, 0 otherwise

CRYPT_BLOWFISH

Set to 1 if the Blowfish encryption with a 16 character salt starting with $2$ or $2a$ is supported, 0 otherwise0

HTML_SPECIALCHARS

HTML_ENTITIES

ENT_COMPAT

ENT_QUOTES

ENT_NOQUOTES

CHAR_MAX

LC_CTYPE

LC_NUMERIC

LC_TIME

LC_COLLATE

LC_MONETARY

LC_ALL

LC_MESSAGES

STR_PAD_LEFT

STR_PAD_RIGHT

STR_PAD_BOTH

PHP Arithmetic Operators

Operator

Name

Description

Example

Resultx + y

Addition

Sum of x and y

2 + 2

4

x – y

Subtraction

Difference of x and y

5 – 2

3

x * y

Multiplication

Product of x and y

5 * 2

10

x / y

Division

Quotient of x and y

15 / 5

3

x % y

Modulus

Remainder of x divided by y

5 % 2

10 % 8

10 % 21

2

0– x

Negation

Opposite of x

– 2

a . b

Concatenation

Concatenate two strings

"Hi" . "Ha"

HiHa

PHP Assignment OperatorsThe basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the expression on the right. That is, the value of "$x = 5" is 5.

Assignment

Same as…

Descriptionx = y

x = y

The left operand gets set to the value of the expression on the right

x += y

x = x + y

Addition

x -= y

x = x – y

Subtraction

x *= y

x = x * y

Multiplication

x /= y

x = x / y

Division

x %= y

x = x % y

Modulus

a .= b

a = a . b

Concatenate two strings

PHP Incrementing/Decrementing Operators

Operator

Name

Description++ x

Pre-increment

Increments x by one, then returns x

x ++

Post-increment

Returns x, then increments x by one

— x

Pre-decrement

Decrements x by one, then returns x

x —

Post-decrement

Returns x, then decrements x by one

PHP Comparison OperatorsComparison operators allows you to compare two values:

Operator

Name

Description

Examplex == y

Equal

True if x is equal to y

5==8 returns false

x === y

Identical

True if x is equal to y, and they are of same type

5==="5" returns false

x != y

Not equal

True if x is not equal to y

5!=8 returns true

x <> y

Not equal

True if x is not equal to y

5<>8 returns true

x !== y

Not identical

True if x is not equal to y, or they are not of same type

5!=="5" returns true

x > y

Greater than

True if x is greater than y

5>8 returns false

x < y

Less than

True if x is less than y

5<8 returns true

x >= y

Greater than or equal to

True if x is greater than or equal to y

5>=8 returns false

x <= y

Less than or equal to

True if x is less than or equal to y

5<=8 returns true

PHP Logical Operators

Operator

Name

Description

Examplex and y

And

True if both x and y are true

x=6

y=3

(x < 10 and y > 1) returns truex or y

Or

True if either or both x and y are true

x=6

y=3

(x==6 or y==5) returns truex xor y

Xor

True if either x or y is true, but not both

x=6

y=3

(x==6 xor y==3) returns falsex && y

And

True if both x and y are true

x=6

y=3

(x < 10 && y > 1) returns truex || y

Or

True if either or both x and y are true

x=6

y=3

(x==5 || y==5) returns false! x

Not

True if x is not true

x=6

y=3

!(x==y) returns true

PHP Array Operators

Operator

Name

Descriptionx + y

Union

Union of x and y

x == y

Equality

True if x and y have the same key/value pairs

x === y

Identity

True if x and y have the same key/value pairs in the same order and are of the same type

x != y

Inequality

True if x is not equal to y

x <> y

Inequality

True if x is not equal to y

x !== y

Non-identity

True if x is not identical to y

PHP – Multidimensional Arrays

A multidimensional array is an array containing one or more arrays.

In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.

Example

In this example we create a multidimensional array, with automatically assigned ID keys:

$families = array

(

"Griffin"=>array

(

"Peter",

"Lois",

"Megan"

),

"Quagmire"=>array

(

"Glenn"

),

"Brown"=>array

(

"Cleveland",

"Loretta",

"Junior"

)

);The array above would look like this if written to the output:

Array

(

[Griffin] => Array

(

[0] => Peter

[1] => Lois

[2] => Megan

)

[Quagmire] => Array

(

[0] => Glenn

)

[Brown] => Array

(

[0] => Cleveland

[1] => Loretta

[2] => Junior

)

)Example 2

Lets try displaying a single value from the array above:

echo "Is " . $families[‘Griffin’][2] .

" a part of the Griffin family?";The code above will output:

Is Megan a part of the Griffin family?