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

  • Home
  • SEARCH
  • 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 8564687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:15:18+00:00 2026-06-11T17:15:18+00:00

I’m bringing an array into jquery from php, on a wordpress website. It is

  • 0

I’m bringing an array into jquery from php, on a wordpress website. It is a multidimensional array that looks like this after I convert into $jqueryArray (taken from console.log)

2 : Object { max=” 10″, min=” 500 “, number=” 2 “}

3 : Object { max=” 15″, min=” 750 “, number=” 3 “}

4 : Object { max=” 8″, min=” 400 “, number=” 4 “}

5 : Object { max=” 12″, min=” 700 “, number=” 5 “}

1 : Object { max=” 10″, min=” 500 “, number=”1 “}

The code is as follows:

 jQuery(function() {
    jQuery('.wpsc_select_variation').change(function(){

        var arrayFromPHP = <?php echo json_encode($alt_tables) ?>;
        var $jqueryArray = {};

            jQuery.each(arrayFromPHP, function (key, value) {
                $jqueryArray[key] = {};
                $jqueryArray[key] = value;
            });
        console.log($jqueryArray);

        // clears the div that we will type the Table Minimum order too
        jQuery('#table-details').empty();
        var $selectedName;

        // returns an integer, specific to the Table # selected
        $selectedName = jQuery(this).find(':selected').text().replace('Table ', '');

        console.log($jqueryArray.$selectedName);

        var $newDetails = 'Table minimum order: ';
        jQuery('#table-details').append( $newDetails );
    });

});

For some reason $jqueryArray.$selectedName is undefined. I can see that $jqueryArray has 5 keys, numbered 1 through 5, but even when i try console.log($jqueryArray.1); I get undefined. I can’t seem to figure out how to call the number from the array. Basically I want

$jqueryArray[$selectedName][min]
I’ve tried $jqueryArray[$selectedName] in the console.log and receive undefined as well

I added a jsfiddle http://jsfiddle.net/kzuyd/14/

I took the <?php echo json_encode($alt_tables) ?> and just added it as the variable, since php doesn’t work in jsfiddle. Hopefully it works the same..

  • 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-11T17:15:19+00:00Added an answer on June 11, 2026 at 5:15 pm

    Updated jsFiddle

    jQuery(function() {
        var arrayFromPHP = '{"1 ":{"note":null,"max":" 10","min":" 500 ","number":"1 "}," 2 ":{"note":null,"max":" 10","min":" 500 ","number":" 2 "}," 3 ":{"note":null,"max":" 15","min":" 750 ","number":" 3 "}," 4 ":{"note":null,"max":" 8","min":" 400 ","number":" 4 "}," 5 ":{"note":null,"max":" 12","min":" 700 ","number":" 5 "}}';
    
        var $jqueryArray = {};
    
        // you must parse `arrayFromPHP`, it's not actually an array now
        // it's a JSON string
        jQuery.each(JSON.parse(arrayFromPHP), function(key, value) {
    
            // your keys have spaces at the end of them e.g. "1 "
            // trim them first
            $jqueryArray['Table' + key.trim()] = {};
            $jqueryArray['Table' + key.trim()] = value;
        });
    
        jQuery('.wpsc_select_variation').change(function() {
    
            jQuery('#table-details').empty();
            jQuery('#table-minimum').empty();
            var $selectedName;
    
            $selectedName = jQuery(this)
                .find("option:selected")
                .text()
                .replace(/\s/g, '');
                // to replace all spaces, use the regex shown
    
            var $newDetails = 'The selected name: ' + $selectedName + '';
            jQuery('#table-details').append($newDetails);
    
            // use obj["min"] to get the minimum
            var $tableMin = '<br /><br />The table minimum is: ' +
                            $jqueryArray[$selectedName]["min"] + '';
            jQuery('#table-minimum').append($tableMin);
        });
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I know there's a lot of other questions out there that deal with this

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.