public function tournaments($date, $timestamp){
$requests = $this->request("//$date/json?_=$timestamp");
// $result = [];
// foreach ($requests['sportItem']['tournaments'] as $key => $request){
// $result['tournament'] .= $request['tournament']['name'];
// $result['tournament'] .= $request['tournament']['uniqueId'];
// $result[] = $request['category']['name'];
// $result[] = $request['category']['id'];
// $result[] = $request['season']['year'];
// }
return $requests['sportItem']['tournaments'];
}
<?php
namespace app\controllers;
use yii\web\Controller;
use app\components\parseTennis;
class TennisController extends Controller
{
protected $header =заголовки
];
protected $referer = 'сайт';
public function actionIndex(){
$tennis = parseTennis::app("https://www.sofascore.com/tennis")
->set(CURLOPT_REFERER, $this->referer)
->set(CURLOPT_USERAGENT, $this->header);
$result = $tennis->tournaments(date("Y-m-d"), time('d', 'm', 'Y'));
return $this->render('index', ['result' => $result]);
}
}
[0] => Array
(
[tournament] => Array
(
[name] => Roland Garros, Paris, France
[slug] => roland-garros-paris-france
[id] => 66712
[uniqueId] => 2480
[uniqueName] => Roland Garros
)
[category] => Array
(
[name] => ATP
[slug] => atp
[priority] => 7
[id] => 3
[flag] => atp
)
[season] => Array
(
[name] => 2019 French Open Men Singles
[slug] => 2019-french-open-men-singles
[year] => 2019
[id] => 20188
)
)
<?php for($i = 0; $i <= count($categorys); $i++):?>
<?foreach ($categorys as $category):?>
<?php if($i == 0):?>
<div class="<?= $category['class']?>">
<a href="single.html" class="b-link-stripe b-animate-go thickbox">
<img class="img-responsive" src="<?= $category['img']?>" alt="">
<div class="b-wrapper">
<h3 class="b-animate b-from-top top-in b-delay03 ">
<span><?= $category['name']?></span>
</h3>
</div>
</a>
</div>
<?php endif;?>
<?php endforeach;?>
<?php endfor;?>
работать с массивом можно и без цикла.