PHP实现url参数组合字符串与数组相互转换

 
 
$data = array(
  'name' => 'tom',
  'sex' => 1,
  'channel' => 'ty'
);
 
 

  

数组转url参数字符串

$queryStr = http_build_query($data);

echo query_str;
 
 

  

 执行结果:
name=tom&sex=1&channel=ty
 
 

url参数字符串转数组

parse_str($query_str,$query_arr);

print_r($query_arr);
 
 

  

执行结果:
array(
  name => tom,
  sex => 1,
  channel => ty
)
 
 

  

 

猜你喜欢

转载自www.cnblogs.com/qhorse/p/10070799.html