-3

I have a form that asks for comma separated phone numbers, for example, if user enters following in "Phone" field:

9999999999,8888800000,7777788888

Then want to store them as an array just like:

$contacts = array ("9999999999","8888800000","7777788888");

How can I do that?

I tried:

$contacts = array();
if (is_array(@$_POST['phone']))
{
    foreach($_POST['phone'] as $one)
    {
        $contacts[] = basename($one);
    }
}
Aman
  • 1

2 Answers2

2
$myArray = explode(',', '9999999999,8888800000,7777788888');
SuperManSL
  • 1,306
  • 2
  • 12
  • 17
0

You will have to fetch the form input with the global variable called $_POST, $_POST listens to the name of the html element. Let's say we got

<form method="POST">
  <input type="text" name="phoneNumber1" />
  <input type="text" name="phoneNumber2" />
  <input type="text" name="phoneNumber3" />
</form>

Then we are able to fetch the data in it like this.

$contacts = array($_POST['phoneNumber1'], $_POST['phoneNumber2'], $_POST['phoneNumber3']);
Jordy
  • 948
  • 2
  • 9
  • 28