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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:40:45+00:00 2026-05-19T15:40:45+00:00

I am creating a json array in PHP like this (it’s inside a class):

  • 0

I am creating a json array in PHP like this (it’s inside a class):

$STH = $DBH->query("SELECT ID,title,content FROM table WHERE ID= '".$ID."' ");
$querycount = $STH->rowCount();
if($querycount!=0):
    $STH->setFetchMode(PDO::FETCH_OBJ); 
    while( $row = $STH->fetch()) :
        $thread[$row->ID]['title'] = $row->title;
        $thread[$row->ID]['content'] = $row->content;
    endwhile;
    $this->querycount = $querycount;
    $this->thread = json_encode($thread);
 else:
    $this->querycount = $querycount;
 endif;

But I seem to get “strange” decodes the other end. I cannot actually reference the array by key’s;

So far it will let me do this: (Where af_threads is the class name and $key id the ID in the table query)

$threads = new af_threads($key,$DBH);
$threads = json_decode($threads->thread); 
foreach($threads as $key1=>$thread): 
    foreach($thread as $key2=>$val):  
        echo $key2; 
        echo $val; 
    endforeach;
    echo '<hr />';
endforeach;

But what it will not let me do is something like this

$threads[$key]['title']

I’m not sure why. As the class builds i.e. with more rows etc. I will need to call specific rows in specific places. i.e. $threads[$key]['newrow'], $threads[$key]['newrow2'], and or to manipulate a row with say substr(); etc.

Yes I know I could just echo out an array without json, but eventually I want to add cross domain functionality with JQuery getJSON() …

Have I got it all wrong?

  • 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-19T15:40:45+00:00Added an answer on May 19, 2026 at 3:40 pm

    By default, json_decode() returns stdClass, modify second line with

    $threads = json_decode($threads->thread, true)
    

    and you will get an associative array and be able to reference it by keys, $threads[$key]['title'] for example.

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

Sidebar

Related Questions

I'm creating a JSON object like tags = {jon:[beef,pork],jane:[chicken,lamb]}; which was generated using php
I'm creating a JSON string from the results of a mySQL query in PHP.
This is my code for creating Json response for jqGrid and for new keyword
what I am doing is creating a form using JSON this form can then
I'm creating a JSON feed with PHP using echo json_encode($my_array) . The resulting string
I am creating a JSON array exactly as follows (bar using mathrandom). For example
I am creating a multidimensional array for sections / rows based on json data
I have a php file that is creating a array of everything in my
I'm creating JSON encoded data from PHP arrays that can be two or three
How can I access a JSON array from a PHP variable in an external

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.