unraveling a 'foreach'

Hi again. I have some code that was being used to examine a series of tweets and then use a foreach loop to display information about them as such:

[php]$tweets = $connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets."&include_rts=".$include_rts."&exclude_replies=”.$ignore_replies);

$tweetData = json_decode(json_encode($tweets), true);

foreach ($tweetData as $tweet) {
echo '
User: '.$twitteruser;
echo '
ID: ’ . $tweet[‘id_str’];
echo '
Tweet: ’ . $tweet[‘text’];

echo “

”;
}[/php]

Now, however, I am only grabbing ONE tweet so I don’t need the foreach loop anymore. However, I don’t know the syntax to echo the data of the single tweet that I am calling.

Sorry newb here :frowning: Thanks!

If you’re on PHP 5.4 or newer:
[php]$tweets = $connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets."&include_rts=".$include_rts."&exclude_replies=”.$ignore_replies);

$tweet = json_decode(json_encode($tweets), true)[0];

echo '
User: '.$twitteruser;
echo '
ID: ’ . $tweet[‘id_str’];
echo '
Tweet: ’ . $tweet[‘text’];
echo “

”;[/php]

If you’re on a older version of PHP:
[php]$tweets = $connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets."&include_rts=".$include_rts."&exclude_replies=”.$ignore_replies);

$tweetData = json_decode(json_encode($tweets), true);
$tweet = $tweetData[0];

echo '
User: '.$twitteruser;
echo '
ID: ’ . $tweet[‘id_str’];
echo '
Tweet: ’ . $tweet[‘text’];
echo “

”;[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service