How to pass an array in urlencode in PHP?

In PHP, you can use the http_build_query function to convert an array into a URL-encoded query string.

$data = array(
    'param1' => 'value1',
    'param2' => 'value2',
);

$queryString = http_build_query($data);

$url = 'http://example.com/?' . $queryString;

This will generate the following URL: http://example.com/?param1=value1&param2=value2.

To send an array as data for a POST request, you can use the http_build_query function to convert the array into a URL-encoded query string and send it as the request body.

$data = array(
    'param1' => 'value1',
    'param2' => 'value2',
);

$postData = http_build_query($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_exec($ch);
curl_close($ch);

This will send a POST request to http://example.com with the request body as param1=value1&param2=value2.

bannerAds