PROGRAMMING

  minte9
MEMORYApp




S R Q
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Questions    
Last update: 7 days ago
Modify