Sep 24, 2013, by admin
Hi all today we are going to see how to convert a PHP array to a query string.As we know that PHP is very rich with its build in functions, it has very useful function http_build_query() to convert a PHP array to a query string.
Generate a URL query string from a PHP array
First let us take a look at the following PHP array:
<?php
$data = array(
‘apikey’=>‘Btcs01’,
‘user’=>‘abcd’,
‘email’=>‘sam.php@example.com’
);
?>
Now let’s take a look at how we can convert above array to a query string using our PHP function http_build_query():
<?php
echo http_build_query($data);
?>
OUTPUT:
apikey=Btcs01&user=abcd&email=sam.php%40example.com