- 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
Value Exists
Check if a value exists in an array.
/**
* Check if value exists in arrray with isset
*/
$A = [1, 2];
$B = ['a'=>1, 'b'=>NULL];
var_dump( in_array(1, $A) ); // true
var_dump( isset($B['b']) ); // false
var_dump( isset(['a'=>1]['b']) ); // false
Array Search
Array search may return false, always use indentical operator.
/**
* array_search()
*
* The search may return false
* Always use identical operator
*/
$A = [1,2,3,4];
echo (array_search(4, $A)); // 3
echo (array_search(5, $A) == 0) == true; // 1 - Incorrect
echo (array_search(5, $A) === 0) === false; // 1 - Correct
Keys
If specified, only the keys for that value are returned.
/**
* array_keys()
*
* Has a search value option
*/
$A = ['a', 'b', 'a', 'c', 'a', '0', false];
print_r(array_keys($A)); // 0, 1, 2, 3, 4, 5, 6
print_r(array_keys($A, 'a')); // 0, 2, 4
Last update: 530 days ago