fork download
  1. <?php
  2.  
  3. function linearSearch(array $array, $value) {
  4. $length=count($array);
  5. $s = null;
  6. for ($i=0;$i<$length;$i++) {
  7. if($array[$i] == $value){
  8. $s= $i;
  9. break;
  10. }
  11. }
  12. return $s;
  13. }
  14.  
  15. var_dump(linearSearch([31,
  16. 41,
  17. 59,
  18. 2,
  19. 6,
  20. 41,
  21. 59,
  22. 58], 59));
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
int(2)