1.2.1070. Searching For Multiple Keys¶
array_search() and array_keys() find keys in an array. array_search() returns the first key that match a value, while array_keys() returns all the keys that match a value.
array_search() and array_keys() both accepts a final parameter to set a strict search or not.
<?php
$array = array(0,1,2,3,4,3);
// $id = 3
$id = array_search($array, 3);
// $ids = [3, 5];
$ids = array_keys($array, 3);
?>
1.2.1070.1. Suggestions¶
Use array_keys() to find multiple keys in an array
Use array_keys() to find a unique key in an array
1.2.1070.2. Specs¶
Short name |
Structures/ArraySearchMultipleKeys |
Rulesets |
|
Exakat since |
2.2.0 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Available in |