I've learned that the output is quite crazy, in terms of the arrays at least x.x
This is the PHP array that the jSON object is converted to, I used print_r to output the whole thing to show you..
Code:
Array ( [count] => 1 [threads] => Array ( [14] => Array ( [thread_id] => 14 [node_id] => 4 [title] => Testing another [reply_count] => 0 [view_count] => 0 [user_id] => 59 [username] => Faeron [post_date] => 1369261979 [sticky] => 0 [discussion_state] => visible [discussion_open] => 1 [discussion_type] => [first_post_id] => 25 [first_post_likes] => 0 [last_post_date] => 1369261979 [last_post_id] => 25 [last_post_user_id] => 59 [last_post_username] => Faeron [prefix_id] => 0 [content] => Array ( [count] => 1 [content] => Array ( [25] => Array ( [post_id] => 25 [thread_id] => 14 [user_id] => 59 [username] => Faeron [post_date] => 1369261979 [message] => this is another thread [ip_id] => 272 [message_state] => visible [attach_count] => 0 [position] => 0 [likes] => 0 [like_users] => a:0:{} [warning_id] => 0 [warning_message] => ) ) ) ) ) )
So what do I feel the problem is?
Well first off, you have an array under 'threads' and that array has another called '14'. The 14 represents the thread ID, however, how am I suppose to grab variables when I don't know the thread ID prior to outputting it? What I am trying to say is that the array's name is a variable that changes, and I cannot get that changed variable without knowing the thread id.
For example
To get the title of the thread I use this
Code:
$phpNews_array['threads']['14']['title']
But let's say that thread is no longer the latest thread, the code above becomes obsolete. Because the new thread's title, is not accessible by that code, because the array's name is now the new thread_id and not '14'.
I can't make my php code work for all threads because I don't have access to the thread_id unless I know the thread_id, which doesn't work x.x
If there is any other way to go about this, please tell me. I still find this a little annoying.
Furthermore, to get the message of the thread... I have to do the following..
Code:
$phpNews_array['threads']['14']['content']['content']['25']['message']
Again the number '25' is the post ID, which I don't have access to until I am into that array.
I am assuming you would loop through arrays or something of that sort?
EDIT: Using the following works
Code:
reset($phpNews_array);
$first = array_keys($phpNews_array['threads']);
print_r($first);
$first = $first[1];
$second = array_keys($phpNews_array['threads'][$first]['content']['content']);
$second = $second[0];
echo $phpNews_array['threads'][$first]['content']['content'][$second]['message'];