Detailed explanation of PHP sequential search

小云云
Release: 2023-03-20 14:36:02
Original
1293 people have browsed it

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template