我覺得這是你在想什麼......
<?php
for ($tmp = 0; $tmp < 10 && $tmp < count($reviews); $tmp++) {
if ($reviews[$tmp]['freshness'] == 'fresh') {
echo '<img src="assets/images/fresh.png" class="rating" title="Fresh" alt="Fresh" />';
} else {
echo '<img src="assets/images/rotten.png" class="rating" title="Rotten" alt="Rotten" />';
}
echo '<li>' . $reviews[$tmp]['quote'] . '</li>';
}
?>
ETA:看着API和一個固定夫婦的事情。
ETAx2:對於那些希望看到來自API的JSON回報的例子...
{
"total": 41,
"reviews": [
{
"critic": "Joe Baltake",
"date": "2010-07-27",
"freshness": "fresh",
"publication": "Passionate Moviegoer",
"quote": "'Toy Story 3': Alternately affecting, hilarious and heartbreaking and the most original prison-escape movie ever made",
"links": {
"review": "http://thepassionatemoviegoer.blogspot.com/2010/07/perfectimperfect.html"
}
},
{
"critic": "Rafer Guzman",
"date": "2010-07-06",
"freshness": "fresh",
"publication": "Newsday",
"quote": "It's sadder and scarier than its predecessors, but it also may be the most important chapter in the tale.",
"links": {
"review": "http://www.newsday.com/entertainment/movies/toy-story-3-andy-grows-up-1.2028598"
}
},
{
"critic": "Richard Roeper",
"date": "2010-06-30",
"original_score": "5/5",
"freshness": "fresh",
"publication": "Richard Roeper.com",
"quote": "The best movie of the year so far.",
"links": {
"review": "http://www.richardroeper.com/reviews/toystory3.aspx"
}
},
...
完美的,當我解析到底部的foreach,而不是試圖將它分配給$新鮮時,它的工作原理。我會在大約8分鐘內通過stackoverflow讓我回答這個問題。再次感謝! –
值得注意的是,「漂亮」的例子中你沒有正確設置標題和替代文字。 ;) – Luke