开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜