foreach ($array['data'] as $item) {
$sites = $item['sites'];
foreach ($sites as $site) {
if ($site['site_key'] === 'unibet') {
$item['odds'] = $site['odds']['spreads']['odds'];
$item['points'] = $site['odds']['spreads']['points'];
}
}
$result[] = [
'sport_key' => $item['sport_key'],
'teams' => $item['teams'],
'odds' => isset($item['odds']) ? $item['odds'] : '',
'points' => isset($item['points']) ? $item['points'] : '',
];
}
'odds' => isset($item['odds']) ? $item['odds'] : '',
'points' => isset($item['points']) ? $item['points'] : '',
$array = json_decode($input, true);
foreach ($array['data'] as $item) {
$sites = $item['sites'];
foreach ($sites as $site) {
if ($site['site_key'] === 'onexbet') {
$item['odds'] = $site['odds']['spreads']['odds'];
$item['points'] = $site['odds']['spreads']['points'];
}
}
$result[] = [
'sport_key' => $item['sport_key'],
'teams' => $item['teams'],
'spreads' => isset($item['spreads']) ? $item['spreads'] : '',
];
}
Array
(
[sport_key] => soccer_korea_kleague1
[sport_nice] => K League 1
[teams] => Array
(
[0] => FC Seoul
[1] => Gangwon FC
)
[commence_time] => 1589095800
[home_team] => Gangwon FC
[sites] => Array
(
[0] => Array
(
[site_key] => onexbet
[site_nice] => 1xBet
[last_update] => 1588444825
[odds] => Array
(
[spreads] => Array
(
[odds] => Array
(
[0] => 5
[1] => 1.155
)
[points] => Array
(
[0] => -1.5
[1] => 1.5
)
)
)
)
)
[sites_count] => 1
)
[0] => Array
(
[site_key] => onexbet
[site_nice] => 1xBet
[last_update] => 1588433053
[odds] => Array
(
[spreads] => Array
(
[odds] => Array
(
[0] => 3.38
[1] => 1.33
)
[points] => Array
(
[0] => -1.5
[1] => 1.5
)
)
)
)
)
foreach ($array['data'] as $item) {
$sites = $item['sites'];
foreach ($sites as $site) {
if ($site['site_key'] === 'unibet') {
$item['spreads'] = $site['odds']['spreads']['odds']['points'];
}
}
$result[] = [
'sport_key' => $item['sport_key'],
'teams' => $item['teams'],
'spreads' => isset($item['spreads']) ? $item['spreads']: '',
'odds' => isset($item['odds']) ? $item['odds']: '',
'points' => isset($item['points']) ? $item['points']: '',
];
}
function grabBookerDataspreads(array $dataspreads, string $bookerName): array {
return array_map(function(array $item) use ($bookerName) {
// Собираем результирующий объект события
$event = new \stdClass();
$event->sport_nice = $item['sport_nice'] ?? null;
$event->teams = $item['teams'] ?? [];
// Из данных по разным букмекерам оставляем h2h, который нам нужен
$bookersData = array_column($item['sites'], NULL, 'site_key');
$event->spreads = $bookersData[$bookerName]['odds']['spreads'] ?? [];
return $event;
}, $dataspreads['data'] ?? []);
}