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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:00:40+00:00 2026-06-17T11:00:40+00:00

I have a json file in format { list : { 1 : {

  • 0

I have a json file in format

{
    "list" : {
           "1" : {
                "thing1" : "description",
                "thing2" : "description",
                "thing3" : "description"
            },
           "2" : {
                "thing1" : "description",
                "thing2" : "description",
                "thing3" : "description"
            },
            etc.

}

I need to search through and return data based on the description of thing 2 but I also need to then return the number of the list. Problem is the json file comes in with the numbers all out of order so I can’t just increment a variable as I go through them all.

currently I have my code setup like this:

$json = json_decode($response);
foreach($json->list as $item) {
        $i++;
        if($item->thing2 == "description") {
            echo "<p>$item->thing1</p>";
            echo "<p>$item->thing2</p>";
            echo "<p>$item->thing3</p>";
            echo "<p>position: $i</p><br /><br />";
        }
    }

unfortunately because the positions are out of order everytime the $i variable is retuning the wrong position. How can I return the title of the item that has the proper thing2 description.

  • 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-17T11:00:42+00:00Added an answer on June 17, 2026 at 11:00 am

    The setting the second parameter of json_decode() to TRUE returns an associative array which is a bit more conducive to what you want to do:

    $json = json_decode($response, TRUE);
    foreach($json['list'] as $key => $item) {
        if($item['thing2'] == "description") {
            echo "<p>$item['thing1']</p>";
            echo "<p>$item['thing2']</p>";
            echo "<p>$item['thing3']</p>";
            echo "<p>position: $key</p><br /><br />";
        }
    }
    

    Should do the trick.

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

Sidebar

Related Questions

I have a text file that contains cached data in JSON format. I'm trying
I have some data in JSON format in a text file as below. I
I have file in json format of world-countries I want to change it to
I have an XSLT stylesheet that transforms an XML file to JSON format and
I have a configuration file in the following JSON format: { key1: value1, key2:
I have an external file in php, outputed as json format I want the
I have a Google Chrome Bookmark file, and it's in JSON format { checksum:
i have this data cennik.json file: { waluta: PLN, vat: 1.23, 00101: { cena:
I have JSON file in below format. I want to get value i.e. (mouse,
I have a json file and I assume that I do not know anyting

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.