php 数组与URL相互转换

php为了数组与url参数相互转换提供了两个函数:

1,数组转换为带&的URL的字符串

  例如:

$arr =['title'=>'我是小白','name'=>'真的很白','text'=>'但是决不放弃'];
$res =urldecode(http_build_query($arr));
var_dump($res);exit;

结果为:string(60) "title=我是小白&name=真的很白&text=但是决不放弃";

2,带&的URL的字符串转换为数组

  例如:

$str = "title=我是小白&name=真的很白&text=但是决不放弃";
parse_str($str, $res); //第一个参数为字符串,第二个参数为结果
var_dump($res);
exit;
原文地址:https://www.cnblogs.com/brady-wang/p/13531960.html