Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:14:57+00:00 2026-05-27T04:14:57+00:00

In php I have the following array: $car[] = array (id=>1, brand=>Audi, price=>7000); $car[]

  • 0

In php I have the following array:

$car[] = array ("id"=>"1", "brand"=>"Audi", "price"=>"7000"); 
$car[] = array ("id"=>"9", "brand"=>"Merc", "price"=>"9000");

With this array I would like to build the following query string:

&brand0=Audi&brand1=Merc&id0=1&id1=9&price0=7000&price0=9000

How can I go about doing this?

Please note that the array may have more results than just the 2 rows, and so that the built querystring should be able to cope with it (also the results being used in this example may vary).

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:14:58+00:00Added an answer on May 27, 2026 at 4:14 am
    $params = array();
    for($i=0;$i<count($car);$i++) {
        $params[] = 'id' . $i . '=' . $car[$i]['id'];
        $params[] = 'brand' . $i . '=' . $car[$i]['brand'];
        $params[] = 'price' . $i . '=' . $car[$i]['price'];
    }
    $string = implode('&', $params);
    

    This will go through, and create the keys with the number on them, and then glue it all together at the end to give you the $string that you were wanting. It will also, just for cleanliness, not have an extra & at the start or end that you might get if you simply append.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is on php I have the following variable on an array Array (
I have the following PHP array: array(Apple, Pear, Grape, Orange) And I'd like to
I have the following JSON array: <?php $json = { status: OK, results: [
All, I have the following array called locations returned by a PHP ajax call
I have a PHP array of associative arrays with the following format: array(1) {
I have the following array, $cart which is structured like so: Array ( [0]
I have the following array: $my_array = array ( 'city' => $this->input->post('city'), 'country' =>
Say I have the following PHP array: $test = array( 'bob' => array( 'age'
I have a question about associative arrays in php. I have following array in
I have the following array (in php after executing print_r on the array object):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.