开发者

PHP - create array from string

开发者 https://www.devze.com 2023-02-07 16:34 出处:网络
I have开发者_运维技巧 a string that looks like: single=Single&multiple=Multiple2&check=check1&radio=radio2

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

精彩评论

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