Firstly sorry If I didn’t write the title correct because I really cant explain it that good.
Okay so I’m making a twitter app and I used this code
if(!empty($_SESSION['username'])){
$twitteroauth = new TwitterOAuth('MY PRIVATE CODE', 'MY PRIVATE CODE', $_SESSION['oauth_token'], $_SESSION['oauth_secret']);
}
$home_timeline = $twitteroauth->get('/statuses/user_timeline');
print_r($home_timeline);
I connected it with my twitter account and this isn’t the full code, part of it. So this echos.
Array ( [0] => stdClass Object ( [created_at] => Wed Oct 10 19:27:42 +0000 2012 [id] => 256113796215603202 [id_str] => 256113796215603202 [text] => Testing a few thing on my twitter app. ) )
And it prints a few other stuff in the array but I cut it. How do I get the value of the text from the array text? Where it says [text] I would like to have the value of it?
I’ve spent atleast 30 minutes searching and I couldn’t find the answer. If it is a simple function already made by php then can you please tell me. If it is a long line of code can you tell me.
I think you are getting tripped up on the fact that you have an array with an object in it. when you access the array[0] you are now interacting with an Object.
the print_r is showing you that [text] is not an index in the array so:
array[‘text’] does not exist. [text] is a property of the stdObject.
so to get the text it would just be $yourArray[0]->text.
note: if you put your print_r or var_dumps between <pre> </pre> tags then they will look better and be less confusing