0

私はこれを解決しようとしている 24 時間ハッカソンにいるので、少し急いでいる場合はすみません。

最初の for each ループは正常に動作します。この URL からカテゴリのリストを取得しています

https://dev.xola.com/api/categories

私はこれでリストをつかみます

$fullurl = "https://dev.xola.com/api/categories"; 
$string .= file_get_contents($fullurl); // get json content
$json_a = json_decode($string, true); //json decoder

次に、これでループします

<?
foreach($json_a as $v)
{?>
echo $v ?}>

次に、各ルックの 2 番目で、この URL からアイテムを取得します。

https://dev.xola.com/api/experiences

最後の URL のカテゴリに一致する

so samething 
$fullurl = "https://dev.xola.com/api/categories"; 
$string .= file_get_contents($fullurl); // get json content
$json_b = json_decode($string, true); //json decoder

これが私が試した完全なループです

 <?
 $i=0;
foreach($json_a as $v)

$i++ {?> echo $v ?

 foreach($json_b as $x){?>
 if($v==$x):   
 echo $v
 endif;
 ?>

}?>
4

2 に答える 2

2

これにより$result、カテゴリが早期に取得されたデータのみを含む配列が作成されます。

<?php
$categories_url = "https://dev.xola.com/api/categories";
$data = file_get_contents($categories_url);
$categories = json_decode($data, true);

$experiences_url = "https://dev.xola.com/api/experiences";
$data = file_get_contents($experiences_url);
$experiences = json_decode($data, true);
$result = array();
foreach ($experiences['data'] as $experience)
{
    if (in_array($experience['category'], $categories))
    {
        $result[] = $experience;
    }
}
print_r($result);

そして、あなたは簡単に結果を読むことができます:

foreach ($result as $item)
{
    echo $item['category'], "\n";
    echo $item['desc'], "\n";
    //... other data available ...
}
于 2013-09-22T13:55:31.777 に答える