Last active
August 29, 2015 14:10
-
-
Save stoimen/94ec4473ac050fb0fedf to your computer and use it in GitHub Desktop.
Sequential Search v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// unordered list | |
$arr = array(1, 2, 3, 3.14, 5, 4, 6, 9, 8); | |
// searched value | |
$x = 3.14; | |
$length = count($arr); | |
$index = null; | |
for ($i = 0; $i < $length; $i++) { | |
if ($arr[$i] == $x) { | |
$index = $i; | |
break; | |
} | |
} | |
if (isset($index)) { | |
return true; | |
} else { | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment