In PHP, you can use the built-in "http_build_query()" function to convert the array into url parameters. The "http_build_query()" function was added to php5. Its function is to convert an array or object into a url parameter and generate a "URL-encoded" request string.
Recommended: "PHP Video Tutorial"
php uses the http_build_query() function to convert the array into url parameter
<?php $data = array( 'foo' => 'bar', 'baz' => 'boom', 'cow' => 'milk', 'php' => 'hypertext processor' ); echo http_build_query($data) . "\n"; echo http_build_query($data, '', '&'); ?>
Output result:
foo=bar&baz=boom&cow=milk&php=hypertext+processor foo=bar&baz=boom&cow=milk&php=hypertext+processor
http_build_query() function introduction
The function of http_build_query() function is to use the given The associative (or subscripted) array generates a URL-encoded request string.
Writing format:
http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
For example:
$data = array("name"=>"callback" , "value"=>"test"); $rescult = http_build_query($data);
We can output $rescutl to get:
name=callback&value=test
What is the use of this? This is To simulate http requests, pass the obtained data data through the function URL-encode, which is usually used in callbacks.
The above is the detailed content of How to convert array into url parameters in php?. For more information, please follow other related articles on the PHP Chinese website!