Good day! Tell me, how can I display words that appear in the two input fields? I just made words from the input fields, but I need to display only the same words.

<form action="" method="post"> <input type="textarea" name="one"/><br> <input type="textarea" name="two" /><br> <input type="submit" name="submit" value="Передать"><br> </form> <?php $a = $_POST['one']; $b = $_POST['two']; echo $a.'<br>'; echo $b; ?> 
  • 1. Break $ a and $ b into words (that is, get two arrays of words) 2. In the loop, go through the first array and check for the presence of the current word in the second array. For the words found make a conclusion. PS Comparing arrays can be done with one function. Description of the functions of working with arrays is here php.net/manual/ru/book.array.php - Visman

1 answer 1

 $a = $_POST['one']; $b = $_POST['two']; $newArray = array_intersect(explode(" ", $a), explode(" ", $b)); foreach($newArray as $item) { echo $item.'<br>'; }