我有这样的json:
{
data: [
{
_id: 6,
Logo: "http://s3-eu-west-1.amazonaws.com/korabia-eg/images/Logos/Leagues/6.png",
matches: [
{
matchId: 1393036,
competitionId: 6,
teamAId: 18299,
teamALogo: "http://www.datasportsgroup.com/images/clubs/50x50/18299.png",
teamBId: 733,
teamBLogo: "http://www.datasportsgroup.com/images/clubs/50x50/733.png",
scoreA: 2,
scoreB: 2,
status: "Played",
timing: "2019-02-15T17:00:00Z",
}
],
}
],
}
并且我需要通过使用foreach将数据添加到SQL表中的方法,
怎么办?
答案 0 :(得分:0)
<?php
$str=file_get_contents("https://www.so3ody.com/api/get_matches_widget?compId=0&dateFrom=2019/2/15&dateTo=2019/2/16&teamId=0&isWeek=true&roundId=0&week=0&seassonId=0");
$ar=json_decode($str,true);// json to array parsing
$data_ar=$ar['data'];//array
//print_r($data_ar);
foreach($data_ar as $key=>$val)
{
echo $_id=$val["_id"]; // fetchi _id
echo "<br>";
echo $_id=$val["Logo"];// fetching Logo
echo "<br>";
$matches_array=$val["matches"];//match array
foreach($matches_array as $key1=>$value1)
{
echo $value1["matchId"];
echo $value1["competitionId"];
}
}
?>