Http_build_query the request string after generating url-encoded
1. Using key-value pairs, associative arrays:
<?php$data = Array (' foo ' = ' bar ', ' baz ' = ' boom ', ' cow ' = ' milk ', ' php ' = ' hypertext ') Processor '); echo Http_build_query ($data);/* Output:
2, the use of digital subscript
<?php$data = Array (' foo ', ' Bar ', ' baz ', ' boom ', ' cow ' = ' milk ', ' php ' = ' hypertext processor '); echo Http_build_query ($data);/* Output: 0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+ Processor*/echo http_build_query ($data, ' myvar_ ');/* Output:
3. Using multidimensional arrays:
<?php$data = Array (' User ' =>array (' name ' = ' Bob Smith ', ' age ' =>47, ' Sex ' = ' M ', ' dob ' = ' 5/12/1956 '), ' pastimes ' =>array (' golf ', ' oper A ', ' poker ', ' rap '), ' Children ' =>array (' Bobby ' =>array (' age ' =>12, ' Sex ' = ' M '), ' Sally ' =>array (' age ' =>8, ' Sex ' = ' F '), ' CEO '); Echo http_build_query ($data, ' flags_ ');/* Output: (Wrapping it for readability) user[name]=bob+smith&user[age]=47&user[sex]=m& amp;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 subscript element in the underlying array "CEO" obtains the prefix, the other number subscript element (Elements such as pastimes) do not need to be prefixed with a valid variable name. */?>
4. Using objects
<?phpclass MyClass { var $foo; var $baz; function MyClass () { $this->foo = ' bar '; $this->baz = ' boom '; }} $data = new MyClass (); Echo http_build_query ($data);/* Output:
HTTP for PHP