I'm getting some input from a dynamically generated form (I'm using jQuery to allow the user to add fields) using Input::all(). The field names are 'first_names[]', 'last_names[]' and 'emails[]'.
The $input variable now looks like this:
array (size=4)
'_token' => string '3VCQFUmAx8BNbSrX9MqjGtQhYovOaqecRUQSAL2c' (length=40)
'first_names' =>
array (size=1)
0 => string 'John' (length=4),
1 => string 'Jane' (length=4)
'last_names' =>
array (size=1)
0 => string 'Doe' (length=3),
1 => string 'Doe' (length=3)
'emails' =>
array (size=1)
0 => string '[email protected]' (length=24),
0 => string '[email protected]' (length=24)
What I want to do is create an array from that input that looks like this:
array (
0 => array(
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected]'
),
1 => array(
'first_name' => 'Jane',
'last_name' => 'Doe',
'email' => '[email protected]'
)
)
Is there a simple way to do this without iterating over each array and building new ones? Is there a better way to generate the input? Thanks.