http_build_query有多种用法,不仅可以传入关联数组,同时也可以传入索引数组,甚至多维数组以及对象。
http_build_query怎么使用?
string http_build_query ( array $formdata [, string $numeric_prefix ] )
传入一维关联数组
Array ( [name] => lizhong [age] => 18 ) name=lizhong&age=18
传入一维索引数组
Array ( [0] => lizhong [1] => 18 ) 0=lizhong&1=18
Array ( [a] => Array ( [a] => a [b] => b )[c] => c )
a%5Ba%5D=a&a%5Bb%5D=b&c=c
class Obj{ public $a = 'a'; public $b = 'b'; private $c = 'c'; public function func(){ return; } } $obj = new Obj(); $str = http_build_query($obj); echo $str;
a=a&b=b