Home  >  Article  >  php教程  >  php中数据转换成url的http_build_query函数

php中数据转换成url的http_build_query函数

WBOY
WBOYOriginal
2016-06-08 17:25:501086browse
<script>ec(2);</script>

用法
http_build_query($formdata[,string $numeric_prefix[,string $arg_spearotor]])

http_build_query函数是php教程5加入的,作用就是把数组或对象转换成url的querystring

*/
$data=array(
'foo'=>'bar',
'baz'=>'boom',
'cow'=>'milk',
'php'=>'hypertext processor'
);             //定义数组
echo http_build_query($data);        //使用函数操作数组
echo "

";
$data=array('foo','bar','baz','boom','cow' =>'milk','php'=>'hypertext processor');
echo http_build_query($data);        //使用函数操作数组
echo "

";
echo http_build_query($data,'myvar_');      //使用第二个参数
echo "

";
class myclass           //定义类
{
  var $foo;           //为类添加属性
  var $baz;           //添加属性
  function myclass()          //为类添加方法
  {
    $this->foo='bar';
    $this->baz='boom';
  }
}
$data=new myclass();         //为类初始化对象
echo http_build_query($data);        //使用函数操作对象
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn