Needle in a Haystack for Php [closed]

PHP’s official documentation is an excellent reference for such, please take a look at that before posting questions like this!

here is what you may need to change in your code:

// Set a name attribute for the submit button
<input type = "submit" value = "submit" name="submit">


<?php
    if(isset($_POST['submit'])) {
      // setup variables
      $haystack = array('cs85','cs60','cs61', 'cs80', 'cs81');
      $needle = strip_tags($_POST['needle']);

      if(!array_search($needle, $haystack)) {
        echo $needle. " Needle Not Found";
      } else {
        echo $needle. " Needle Found!";
      }
    }
?>

W3 Schools has a nice example about a similar search.

Check this out for more details

Leave a Comment