Mustakim
Mustakim

Reputation: 429

How to get multiple values from one input field in php?

I want to enter 3 data separated by a space in one input.

I want to store these 3 data in 3 different variable.

Then I want to use these variables. I'm not understanding how to do this.

Upvotes: 2

Views: 5012

Answers (2)

Mikelo
Mikelo

Reputation: 281

In addition to the answer given above, you can also use the explode() function:

$input  = $_POST['YourFieldName'];
$input_arr = explode(" ", $input);
echo $input_arr[0]; // input 1
echo $input_arr[1]; // input 2 etc...

Upvotes: 0

Bhavik Hirani
Bhavik Hirani

Reputation: 2016

try this

<input type="text" name="inputbox">

<?php 
if(isset($_POST['inputbox'])){
    foreach (explode(' ', $_POST['inputbox']) as $key => $value){
        ${'var'.$key} = $value
    }
}

now you can use $var0, $var1 and $var2

Upvotes: 6

Related Questions