linear search


See On Github

Data

Contributor

Generic placeholder thumbnail

by jay754

in php

Tags

linear, search

Source Code

<?php

function linear_search($arr, $key){
    for($i=0 ; $i < count($arr); $i++){
        if($arr[$i] === $key){
            return $i . "\n";
        }
    }

    return -1 . "\n";
}

?>