-1
我不確定我所問的內容是否有意義,但我會盡力解釋我所能做到的。我有我已經通過使用捲曲和,對象打印出像這樣的一個部分打印出一些JSON數據,循環遍歷數組找到某個單詞然後打印所有包含單詞的對象
國內啤酒(0.5升草案),餐館
然後下一行是
新鮮的麪包白麪包(500克),市場
我想知道是否有可能循環通過數據數組和看到哪些部分包含單詞「餐館」及組它們放在一起成可變,然後爲makets做同樣的事情?
這是我對陣列碼到目前爲止
$json = json_decode($r);
$json->monthLastUpdate;
// search through data for printing
echo "<div id='results'>";
echo "<h2> Prices for $country </h2>";
foreach($json->prices as $prices) {
// echos out the selected items into a list
echo "</div>";
echo "<p>" . $prices->item_name . " <br><b> Average price </b>";
$pricedata ="$prices->average_price";
//rounds the numbers down to readable format
echo number_format((float)$pricedata, 2, '.', '');
echo "(";
echo $currency;
echo ")";
這是JSON數據,我從查詢
{
"monthLastUpdate": 3,
"contributors": 4424,
"name": "India",
"prices": [
{
"average_price": 0.984819890047,
"item_name": "Meal, Inexpensive Restaurant, Restaurants",
"highest_price": 1.96963978009,
"item_id": 1,
"lowest_price": 0.64013292853
},
{
"average_price": 4.92409945023,
"item_name": "Meal for 2, Mid-range Restaurant, Three-course, Restaurants",
"highest_price": 7.87855912037,
"item_id": 2,
"lowest_price": 3.0005
},
該逗號的位置如何一致 - 您可以通過它來分割線嗎?也許發佈一點你的JSON代碼 –
我添加了JSON使其更有意義,我試圖得到它,所以最後與餐廳的位將在一個單獨的組中,同樣將用於市場等。我不能刪除逗號,因爲數據來自外部來源 – shrp
'list($ item_name,$ restaurant_name,$ type)= explode(',',$ prices-> item_name);' –