ranslobo ranslobo - 3 months ago 30
PHP Question

PHP Build url query from array

I'm trying to build URL query from an Array that looks like that:

$serials = ['3804689','3801239','3555689','3804687','1404689','6804689','8844689','4104689','2704689','4604689'];

I would like to get query like that:


(you get the idea)

I'm trying to use
http_build_query($serials, 'serial', '&');
but it adds the numeric index to the prefix 'serial'.

Any idea how to remove that numeric index?


Maybe use a foreach:

$get = "localhost/get?serial=" . $serials[0];
unset( $serials[0] );
foreach( $serials AS serial ){
    $get .= "&serial=$serial;