Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert POST array back to POST string data

Tags:

arrays

post

php

When you do the following in an HTML form:

<input name="one[]" value="foo" />
<input name="one[]" value="bar" />
<input name="two[key]" value="something" />

and submit the form to a PHP page, The $_POST array will look as follows:

array(
    'one' => array(
        0 => 'foo',
        1 => 'bar'
    ),
    'two' => array(
        'key' => 'something'
    ),
),

If you look at the header data, though, it will look as follows:

one[]=foo&one[]=bar&two[key]=something

Does anyone have a script with which to convert the PHP array back into the POST data string? urlencode doesn't work as it can't acces arrays...


like image 520
Jrgns Avatar asked Oct 30 '08 16:10

Jrgns


1 Answers

You want http_build_query()

like image 199
Greg Avatar answered Nov 04 '22 13:11

Greg