Home > Article > Backend Development > Detailed explanation of PHP sequential search
Starting from the first record in the table, compare the keywords of the records with the given value one by one. If the keyword of a record is equal to the given value, the search is successful; otherwise, if it goes to the last record The keywords are not equal to the given value, indicating that there is no record in the table and the search was unsuccessful. There does not have to be a logical relationship between the data elements in the table, that is, they can be ordered in any order in the table.
PHP implementation:
function SequelSearch($arr,$key) { for($i=0;$i<count($arr);$i++) { if($arr[$i]==$key) return $i; } return -1;
Related recommendations:
The above is the detailed content of Detailed explanation of PHP sequential search. For more information, please follow other related articles on the PHP Chinese website!