phparraysquery-string

Convert a flat, indexed array to a URL querystring


I have this array ($recip):

Array
(
    [0] => 393451234567
    [1] => 393479876543
)

SMS API provider requires numbers in this format:

recipients[]=393334455666&recipients[]=393334455667

With

$recipients = implode('&recipients[]=',$recip);

I can obtain only this:

393471234567&recipients[]=393459876543

This output is missing the first key declaration.


Solution

  • Just append the initial recipients[]= to the front of your string:

    $recipients = 'recipients[]=' . implode('&recipients[]=',$recip);