Viewed   81 times

I need your help.,

How to pass the array values in query string...

                foreach ( $Cart->getItems() as $order_code=>$quantity ) :
                $pname[]= $Cart->getItemName($order_code);
                $item[]= $Cart->getItemPrice($order_code);
                <form action='expresscheckout.php?amt=<?php echo $total_price; ?>&item_name=<?php echo $pname; ?>&unit=<?php echo $item; ?>&quan=<?php echo $qty; ?>' METHOD='POST'>
<input type='image' name='submit' src='' border='0' align='top' alt='Check out with PayPal'/>

This is my code sample.,for the above sample code i have to pass the query string on my action url that is expresscheckout.php?amt=100.,etc...values are coming under the $pname[],$item[],$qty[].

Expecting output in expresscheckout.php

expresscheckout.php?pname=product1,product2&item=item1,item2&qty=1,2, this....

Thanks in Advance....



Basically, you just need to use PHP's implode function to turn an array into a comma-separated list. i.e. for the $item array:

$item = array('item1', 'item2');
echo implode(',', $item);

Will output:


So, something like this should print a querystring similar to what you want:

echo 'pname='.implode(',', $pname).
     '&item='.implode(',', $item).
     '&qty='.implode(',', $qty);
Monday, August 8, 2022

Here's what I figured out:

Submitting multi-value form fields, i.e. submitting arrays through GET/POST vars, can be done several different ways, as a standard is not necessarily spelled out.

Three possible ways to send multi-value fields or arrays would be:

  • ?cars[]=Saab&cars[]=Audi (Best way- PHP reads this into an array)
  • ?cars=Saab&cars=Audi (Bad way- PHP will only register last value)
  • ?cars=Saab,Audi (Haven't tried this)

Form Examples

On a form, multi-valued fields could take the form of a select box set to multiple:

    <select multiple="multiple" name="cars[]"> 

(NOTE: In this case, it would be important to name the select control some_name[], so that the resulting request vars would be registered as an array by PHP)

... or as multiple hidden fields with the same name:

<input type="hidden" name="cars[]" value="Volvo">
<input type="hidden" name="cars[]" value="Saab">
<input type="hidden" name="cars[]" value="Mercedes">

NOTE: Using field[] for multiple values is really poorly documented. I don't see any mention of it in the section on multi-valued keys in Query string - Wikipedia, or in the W3C docs dealing with multi-select inputs.


As commenters have pointed out, this is very much framework-specific. Some examples:

Query string:



"list_a": "3", 
"list_c": "1,2,3"


 "list_a": [
  "list_b[]": [
  "list_c": "1,2,3"

(Angular discussion)

See comments for examples in node.js, Wordpress,

Maintaining order: One more thing to consider is that if you need to maintain the order of your items (i.e. array as an ordered list), you really only have one option, which is passing a delimited list of values, and explicitly converting it to an array yourself.

Tuesday, December 27, 2022
substr("testers", -1); // returns "s"

Or, for multibytes strings :

substr("multibyte string…", -1); // returns "…"
Wednesday, December 14, 2022
    header("Status: 301 Moved Permanently");
    header("Location:./content/index.html?". $_SERVER['QUERY_STRING']);
Tuesday, September 27, 2022

Your query string should rather look like this:

Monday, September 12, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :