Home  >  Article  >  Backend Development  >  Detailed explanation of PHP sequential search

Detailed explanation of PHP sequential search

小云云
小云云Original
2018-02-28 09:17:481295browse

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:

PHP Bubble sort Binary search Sequential search Detailed explanation of two-dimensional array sorting algorithm function

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn