次のコードは、検索エンジンからの URL、タイトル、およびスニペットに関連付けられた配列を返し、正常に動作します。
$js = json_decode($data);
$blekkoArray = array();
$find = array ('http://','https://','www.');
foreach ($js->RESULT as $item)
{
$blekkoArray[$i]['url'] = str_replace ($find, '', ($item->{'url'}) );
$blekkoArray[$i]['title'] = ($item->{'url_title'});
$blekkoArray[$i]['snippet'] = ($item->{'snippet'});
$i++;
}
print_r ($blekkoArray);
たとえば、各要素をスコアリングできるように、配列に別の値を追加しようとしています。最初の結果のスコアを 100、2 番目の結果を 99、3 番目の結果を 98 などにしたい場合、次のコードは上記と同じように吐き出します。したがって、配列に「スコア」を追加することはできないようです。よろしく
$js = json_decode($data);
$blekkoArray = array();
$find = array ('http://','https://','www.');
foreach ($js->RESULT as $item)
{
$score = 100;
$blekkoArray[$i]['url'] = str_replace ($find, '', ($item->{'url'}) );
$blekkoArray[$i]['title'] = ($item->{'url_title'});
$blekkoArray[$i]['snippet'] = ($item->{'snippet'});
$blekkoArray[$i]['score'];
$i++;
$score--;
}
print_r ($blekkoArray);