-10

I'm try to find out how to proceed if I want to compare a text field value with values from an array?

HTML: I have a textbox, and a Check button

<form id="text_check" method="POST">
  <input type="text" name="postcode" placeholder="e.g. text">
  <button type="button" class="button" name="Check"/>Check</button>
</form>

The logical steps should be: enter text--> click submit button --> the entered text should be compared with a given array, and return with a positive or negative message...

I am a beginner, so any help is welcome!

szabyka21
  • 1
  • 2

2 Answers2

2

I dont know how your code looks like at the moment but i think you need something like this? Please respond if you need something else or if i misunderstood your question

foreach($yourarray as $value) {
    if($string == $value) {
         // same
    }
}
Szenis
  • 4,020
  • 2
  • 21
  • 34
1

You can use in_array function in PHP

if(in_array("your_string", $array)){
    echo "string matched";
}
RNK
  • 5,582
  • 11
  • 65
  • 133