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 9318831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:13:49+00:00 2026-06-19T03:13:49+00:00

I am building an array in JS as such: var slots = {}; $(.taken).each(function(item)

  • 0

I am building an array in JS as such:

       var slots = {}; 

                $(".taken").each(function(item) {

                    var key = $(this).attr("id");
                    slots[key] = "<?php echo $_SESSION['alias']; ?>";

                }); 

                var json = JSON.stringify(slots);
                var date = "<?php echo $_GET['date']; ?>"
             $.ajax({
                type: "POST",
                     url: "controllers/dutyupdate2.php",
                    data:{ array : json, date:  date },
                success : function(response){
                        console.log (response)
                    }//end success
                });//end ajax

In my PHP script I am posting to, I need to decode it to match the following format:

array( 'D1P'=>"JohnC" , 'D6E' => "JohnC")

I get:

Array(
    [D2E] => JohnC
    [D6E] => JohnC
    [D3BU] => JohnC
)

No matter how I decode the array, I get an indexed array with my key as the index.
Am I building the array incorrectly in the JS code or decoding incorrectly?

Thanks in advance

  • 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-06-19T03:13:51+00:00Added an answer on June 19, 2026 at 3:13 am

    This is the format you want, just displayed differently. See this PHP code to verify

    $a = array( 'D1P'=>"JohnC" , 'D6E' => "JohnC");
    print_r($a);
    

    this gives

    Array
    (
        [D1P] => JohnC
        [D6E] => JohnC
    )
    

    as output. So, there’s no need to try or search anything different.

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

Sidebar

Related Questions

In the building process of an array I'm trying to call a function, checkIfNodeExists()
So I am building off of this question about multidimensional associative array of arrays
I am building an array in javascript, using JSON.stringify() on it, and then setting
Often, I am building an array by iterating through some data, e.g.: my_array =
I'm having some problems building an hierarchistic array structure - I have almost got
I´m building a jquery animation from a multidimensional array, and in the callback of
I am building a simple particle system and want to use a single array
I am building two arrays in c# and pass them to a js function
Building an inventory system. I have lots of products and each product has three
I'm building an application which will have dynamic allocated objects of type A each

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.