Alex Alex - 5 months ago 11
PHP Question

PHP - create array from string

I have a string that looks like:

single=Single&multiple=Multiple2&check=check1&radio=radio2


how could I create a array like this:

array(
'single' => 'Single',
'multiple' => 'Multiple2',
'check' => 'check1',
'radio' => 'radio2',
)

Answer

Use parse_str

parse_str('single=Single&multiple=Multiple2&check=check1&radio=radio2', $data);

And in $data you will have your variables.