- BASICS
- Quotes
- Constants
- Control Structures
- Reference
- Number Systems
- VARIABLES
- Definition
- Variable Variable
- Exists
- Type Casting
- OPERATORS
- Aritmetic
- Bitwise
- String
-
Comparison
- Logical
- FUNCTION
- Definition
- Anonymous
- Reference
- Variable Arguments
- ARRAY
- Basics
- Operations
- Create
- Search
- Modify
- Sort
- Storage
- STRING
- String Basics
- String Compare
- String Search
- String Replace
- String Format
- String Regexp
- String Parse
- Formating
- Json
- STREAMS
- File Open
- Read File
- Read Csv
- File Contents
- Context
- Ob_start
- OOP
- Object Instantiation
- Class Constructor
- Interfaces, Abstract
- Resource Visibility
- Class Constants
- Namespaces
- HTTP
- Headers
- File Uploads
- Cookies
- Sessions
Identity
True if only operands are of the same data type and the same value.
/**
* Identical operator
*/
$x1 = 'xn--google.com';
$x2 = 'google.com';
var_dump(stripos($x1, 'xn--') === 0); // true - Correct
var_dump(stripos($x2, 'xn--') == 0); // true - Incorrect
Confusion
It's easy to confuse the assignment operator = for the comparison operator ==
/**
* Comparition operator, prone to error
*/
$a = 10;
$b = 9;
var_dump($a == 10); // true
var_dump(10 == $a); // true, better
if ($b = 10) echo $b; // 10 - Incorrect
Inequality
While the process is clear for numbers, things change a bit for other data types.
/**
* Comparing strings
*
* D > C, a > A
*
* ASCII value of a (97)
* ASCII value of A (65)
*/
var_dump("ABC" > "ABD"); // false
var_dump("apple" > "Apple"); // true
Last update: 531 days ago