Http_build_query string concatenation
Generates a urlencode after the request string.
1. Convert an array to a string after the URL question mark (?)
1<?PHP2 $date=Array(3' Name ' = ' Tane ',4' Sex ' =>1,5' Job ' = ' officer '6' Text ' = ' Hello World '7 );8 Echo Http_build_query($date);9 //Output Name=tane&sex=1&job=officer&text=hello+worldTen?>
2.http_build_query () Adding a digital subscript
$data Array (' name ', ' Tane ', ' sex ', ' job ' = ' officer ', ' text ' = ' Hello World '); Echo Http_build_query ($date, ' remot_ '); // Output Remot_0=name&remote_1=tane&remot_2=sex&job=officer&text=hello+world
3.http_build_query () using a complex array
<?PHP$data=Array(' User ' =Array(' name ' = ' Bob Smith ', ' age ' =>47, ' sex ' = ' M ', ' dob ' = ' 5/12/1956 '), ' pastimes ' =Array(' Golf ', ' opera ', ' Poker ', ' rap '), ' children ' =Array(' Bobby ' =Array(' Age ' =>12, ' sex ' = ' M '), ' sally ' =Array(' Age ' =>8, ' sex ' = ' F ' <br> '), ' CEO '); Echo Http_build_query($data, ' Flags_ '); /*Output: (Wrapping it for readability) user[name]=bob+smith&user[age]=47&user[sex]=m&user[dob]=5%1f12%1f1956& pastimes[0]=golf&pastimes[1]=opera&pastimes[2]=poker&pastimes[3]=rap& children[bobby][age]=12 &children[bobby][sex]=M&children[sally][age]=8& Children[sally][sex]=f&flags_0=ceo Note: Only the number in the underlying array The subscript element "CEO" obtains the prefix, other numeric subscript elements (such as elements under pastimes) do not need to be prefixed with a valid variable name. */?>
4.http_build_query () Working with objects
<?PHPclassMyClass {var $foo; var $baz; functionMyClass () {$this->foo = ' Bar '; $this->baz = ' boom '; } } $data=NewMyClass (); Echo Http_build_query($data); /*Output: Foo=bar&baz=boom*/?>
Http_build_query string concatenation