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',
)
Use parse_str
parse_str('single=Single&multiple=Multiple2&check=check1&radio=radio2', $data);
And in $data you will have your variables.
If this comes from an URL you can have this already as an array in the $_GET or $_POST variables. Otherwise use explode() to convert string to an array.
精彩评论