PHP Skills Tests: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 115: | Line 115: | ||
This is hexidecimal notation. The value is calculated `0 * 1 = '''0'''` + `0 * 16 = '''0'''` + `5 * 256 = '''1280'''`. | This is hexidecimal notation. The value is calculated `0 * 1 = '''0'''` + `0 * 16 = '''0'''` + `5 * 256 = '''1280'''`. | ||
== | == Bitwise operators == | ||
{| class="wikitable" | |||
! Example | |||
! Name | |||
! Result | |||
|- | |||
| `$a & $b` | |||
| And | |||
| Bits that are set in both `$a` and `$b` are set. | |||
|- | |||
| `<nowiki>$a | $b</nowiki>` | |||
| Or (inclusive or) | |||
| Bits that are set in either `$a` or `$b` are set. | |||
|- | |||
| `$a ^ $b` | |||
| Xor (exclusive or) | |||
| Bits that are set in `$a` or `$b` but not both are set. | |||
|- | |||
| `~ $a` | |||
| Not | |||
| Bits that are set in `$a` are not set, and vice versa. | |||
|- | |||
| `$a << $b` | |||
| Shift left | |||
| Shift the bits of `$a` `$b` steps to the left (each step means "multiply by two") | |||
|- | |||
| `$a >> $b` | |||
| Shift right | |||
| Shift the bits of `$a` `$b` bits to the right (each step means "divide by two") | |||
|} | |||
== `is_numeric()` == | == `is_numeric()` == | ||
Revision as of 18:43, 15 March 2016
Operator precedence
| Associativity | Operators | Additional information |
|---|---|---|
| non-associative | clone new
|
clone and new |
| left | [
|
array() |
| right | **
|
arithmetic |
| right | ++ -- ~ (int) (float) (string) (array) (object) (bool) @
|
types and increment/decrement |
| non-associative | instanceof
|
types |
| right | !
|
logical |
| left | * / %
|
arithmetic |
| left | + - .
|
arithmetic and stirng |
| left | << >>
|
bitwise |
| non-associative | < <= >= >
|
comparison |
| non-associative | == != === !== <> <=>
|
comparison |
| left | &
|
bitwise and references |
| left | ^
|
bitwise |
| left | `|
|
bitwise |
| left | &&
|
http://php.net/manual/en/language.operators.logical.php logical] |
| left | ||
|
logical |
| right | ??
|
comparison |
| left | ? :
|
ternary |
| right | = += -= *= /= .= %= &= |= ^= <<= >>= =>
|
assignment |
| left | and
|
logical |
| left | xor
|
logical |
| left | or
|
logical |
| left | ,` | many uses |
Associativity
TK
Hexidecimal values
echo 0x500; 1280
This is hexidecimal notation. The value is calculated 0 * 1 = 0 + 0 * 16 = 0 + 5 * 256 = 1280.
Bitwise operators
| Example | Name | Result |
|---|---|---|
$a & $b
|
And | Bits that are set in both $a and $b are set.
|
`$a | $b
|
Or (inclusive or) | Bits that are set in either $a or $b are set.
|
$a ^ $b
|
Xor (exclusive or) | Bits that are set in $a or $b but not both are set.
|
~ $a
|
Not | Bits that are set in $a are not set, and vice versa.
|
$a << $b
|
Shift left | Shift the bits of $a $b steps to the left (each step means "multiply by two")
|
$a >> $b
|
Shift right | Shift the bits of $a $b` bits to the right (each step means "divide by two")
|
is_numeric()
- Valid values:
"200",".25e4","20,2" - Invalid values: "
$200"
Magical constants
Magical constants are constants that change value depending on where in the code they are placed.
The magical constants in PHP are
__LINE____FILE____DIR____FUNCTION____CLASS____TRAIT____METHOD____NAMESPACE__