Need Help Printing an Array
Posted: Tue Oct 20, 2009 9:51 am
Hello. I'm new to this forum. I thought I give this forum a try. I've been fighting with printing an array for a couple of hours now. I need to be able to display it on the screen, but I can't seem to figure it out. The value of the $json array is:
[{"position":null,"name":"#jobs","query":"#jobs","id":1431729,"created_at":"Thu Aug 27 19:30:55 +0000 2009"},{"position":null,"name":"ubuntu","query":"ubuntu","id":1449458,"created_at":"Fri Aug 28 21:50:21 +0000 2009"},{"position":null,"name":"linux","query":"linux","id":1650471,"created_at":"Sat Sep 12 00:20:18 +0000 2009"},{"position":null,"name":"#wordpress","query":"#wordpress","id":1912615,"created_at":"Tue Sep 29 11:18:41 +0000 2009"}]
This is my code: (I've updated the code. It's an API call to Twitter)
What am I doing wrong?
[{"position":null,"name":"#jobs","query":"#jobs","id":1431729,"created_at":"Thu Aug 27 19:30:55 +0000 2009"},{"position":null,"name":"ubuntu","query":"ubuntu","id":1449458,"created_at":"Fri Aug 28 21:50:21 +0000 2009"},{"position":null,"name":"linux","query":"linux","id":1650471,"created_at":"Sat Sep 12 00:20:18 +0000 2009"},{"position":null,"name":"#wordpress","query":"#wordpress","id":1912615,"created_at":"Tue Sep 29 11:18:41 +0000 2009"}]
This is my code: (I've updated the code. It's an API call to Twitter)
Code: Select all
$contents = @file_get_contents("http://twitter.com/saved_searches.json");
$json = json_decode($contents);
foreach ($json as $saved_search) {
echo $saved_search->name;
}