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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:49:48+00:00 2026-05-25T09:49:48+00:00

I have a PHP object like so: Array ( [Apples] => stdClass Object (

  • 0

I have a PHP object like so:

Array ( 
     [Apples] => stdClass Object ( 
                      [RandomText] => Apples 
                      [RandomNumber1] => 30 
                      [RandomNumber2] => 21 
                 ) 
     [Oranges] => stdClass Object ( 
                      [RandomText] => Oranges 
                      [RandomNumber1] => 20 
                      [RandomNumber2] => 45 
                 ) )

My ultimate goal is to be able to use this with jQuery. In particular, in a form select, once the option is changed to “Apples”, it alerts “RandomString1 is greater than RandomString2”, and when it’s changed to Oranges, it alerts “RandomString1 is smaller than RandomString2” and so on with many more iterations.

My question is, how do I do this? I’ve tried adding this to my PHP:

echo '<script> var json = '. json_encode($myArray).'</script>';

which outputs:

var json = {"Apples":{"RandomText":"Apples","RandomNumber1":"30","RandomNumber2":21},"Oranges":{"RandomText":"Oranges","RandomNumber1":"20","RandomNumber2":45}}

But I cannot figure out how to proceed from here.

Any help, even pointing me where to look, would be greatly appreciated 🙂

  • 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-25T09:49:49+00:00Added an answer on May 25, 2026 at 9:49 am

    You’re almost there…

    $('select').change(function(){
      var fruit = $(this).val();
      if (json[fruit].RandomNumber1 > json[fruit].RandomNumber2) {
        alert(json[fruit].RandomText);
      } else {
        alert('Something else?');
      }
    });
    

    You should probably use Inspector/Firebug to play with the JS console in your browser so you can try things out easily. You can start by just writing json; and seeing what it returns. Then start playing with different ways of navigating the tree.

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

Sidebar

Related Questions

I have a function which returns object array like that: <?php function sth() {
I have a PHP array that looks like this: Array ( [0] => Array
I have a directory structure like the following; script.php inc/include1.php inc/include2.php objects/object1.php objects/object2.php soap/soap.php
I have a PHP web application which uses a MySQL database for object tagging,
We have a PHP project that we would like to version control. Right now
I find myself converting between array and object all the time in PHP application
I have an array in php with Objects containing an id and a parent_id
I have Json object like this { resultArr: [ { ID:1, 0:1, APPROVAL LEVEL:1,
I have PHP configured so that magic quotes are on and register globals are
We have PHP 5.2.6 deployed to c:\php and in that folder there is the

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.