What is the function http_build_query used for in PHP?
The function http_build_query in PHP is used to build a query string from an array of data. This function takes an associative array as input and returns a URL-encoded string with key-value pairs separated by '&'. It is commonly used when constructing URLs for HTTP requests or when working with form data.
```php
$data = array(
'name' => 'John Doe',
'age' => 30,
'city' => 'New York'
);
$queryString = http_build_query($data);
echo $queryString;
```
This code snippet will output: `name=John+Doe&age=30&city=New+York`
Related Questions
- What role does the "umask" and "chmod" functions play in managing file permissions in PHP?
- What common errors can occur when connecting PHP to a DB2 database?
- What best practices should be followed when retrieving data from a database and displaying it in form fields, especially in textarea elements?