-1

I would like to get each item in an array from user input form. The user will input numbers from a single input field separated by space (1 2 3 4) then I get this input and replace the space with commas (1,2,3,4) and add this variable to array however the results returned by $number seems to return the entire value as a single number like this:

1,2,3,4

And not like this:

1
2
3
4

code:

<?php

  $inp_results =$_POST['inp_results'];
  $inp_results_comma = str_replace(' ', ',', $inp_results);
  $number_in_results = array($inp_results_comma); 

  foreach ($number_in_results as $number)
  {
    echo "$number</br>";
  }
Ivan
  • 11,733
  • 5
  • 35
  • 63
TwoStarII
  • 351
  • 2
  • 16

1 Answers1

1
$inp_results = $_POST['inp_results'];
$number_array = explode(' ', $inp_results);
foreach ($number_array as $number) {
    echo "$number</br>";
}
user94559
  • 54,841
  • 6
  • 85
  • 93