@Historian111

Как дотянуться в массиве до ключа, после форич(выдает ошибку)?

Доброе утро! Возникла проблема, для меня очень не понятная.
Форичем
if (is_array($data)) {
                foreach ($data['tournamentInfo']['featuredMatches']['tournaments'] as $match) {

                    echo '<pre>';
                    print_r($match);
                    echo '</pre>';
                }
            }
перебираю получаемый массив.
Получаю такой
массив

Array
(
    [tournament] => Array
        (
            [name] => Stuttgart, Germany
            [id] => 70404
            [uniqueId] => 2483
            [uniqueName] => Stuttgart
            [hasRounds] => 1
        )

    [category] => Array
        (
            [name] => ATP
            [priority] => 7
            [mcc] => Array
                (
                )

            [id] => 3
            [flag] => atp
        )

    [season] => Array
        (
            [name] => 2019 ATP Stuttgart, Germany Men Singles
            [year] => 2019
            [id] => 20243
        )

    [hasEventPlayerStatistics] => 
    [hasEventPlayerHeatMap] => 
    [hasBoxScore] => 
    [events] => Array
        (
            [0] => Array
                (
                    [firstToServe] => 1
                    [roundInfo] => Array
                        (
                            [round] => 27
                            [name] => Quarterfinals
                            [cupRoundType] => 4
                        )

                    [status] => Array
                        (
                            [code] => 100
                            [type] => finished
                        )

                    [winnerCode] => 2
                    [homeTeam] => Array
                        (
                            [name] => Fucsovics M.
                            [slug] => fucsovics-marton
                            [gender] => M
                            [ranking] => 52
                            [national] => 
                            [id] => 47770
                            [subTeams] => Array
                                (
                                )

                        )

                    [awayTeam] => Array
                        (
                            [name] => Raonic M.
                            [slug] => raonic-milos
                            [gender] => M
                            [ranking] => 18
                            [national] => 
                            [id] => 18111
                            [subTeams] => Array
                                (
                                )

                        )

                    [homeScore] => Array
                        (
                            [current] => 0
                            [display] => 0
                            [period1] => 4
                            [period2] => 4
                            [point] => 0
                            [normaltime] => 0
                        )

                    [awayScore] => Array
                        (
                            [current] => 2
                            [display] => 2
                            [period1] => 6
                            [period2] => 6
                            [point] => 0
                            [normaltime] => 2
                        )

                    [time] => Array
                        (
                        )

                    [changes] => Array
                        (
                            [changes] => Array
                                (
                                    [0] => status.code
                                    [1] => status.description
                                    [2] => status.type
                                    [3] => homeScore.normaltime
                                    [4] => awayScore.current
                                    [5] => awayScore.display
                                    [6] => awayScore.period2
                                    [7] => awayScore.point
                                    [8] => awayScore.normaltime
                                    [9] => firstToServe
                                )

                            [changeTimestamp] => 1560532302
                        )

                    [hasHighlights] => 
                    [hasHighlightsStream] => 
                    [hasGlobalHighlights] => 
                    [id] => 8242927
                    [hasTime] => 1
                    [startTimestamp] => 1560527100
                    [statusDescription] => FT
                    [webUrl] => /fucsovics-raonic/lmhsvfu
                    [resultOnly] => 
                    [groundType] => Grass
                )

        )


Теперь мне надо дотянутся до, допустим, $match['events']['id'], но выдает
ошибку
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in C:\OSPanel\domains\sofaYii.local\components\parseTennis.php on line 157. in C:\OSPanel\domains\sofaYii.local\vendor\yiisoft\yii2\web\Response.php:366
Stack trace:
#0 C:\OSPanel\domains\sofaYii.local\vendor\yiisoft\yii2\web\Response.php(339): yii\web\Response->sendHeaders()
#1 C:\OSPanel\domains\sofaYii.local\vendor\yiisoft\yii2\web\ErrorHandler.php(135): yii\web\Response->send()
#2 C:\OSPanel\domains\sofaYii.local\vendor\yiisoft\yii2\base\ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in C:\OSPanel\domains\sofaYii.local\components\parseTennis.php on line 157. in C:\OSPanel\domains\sofaYii.local\vendor\yiisoft\yii2\web\Response.php:366
Stack trace:
#0 C:\OSPanel\domains\sofaYii.local\vendor\yiisoft\yii2\web\Response.php(339): yii\web\Response->sendHeaders()
#1 C:\OSPanel\domains\sofaYii.local\vendor\yiisoft\yii2\base\Application.php(392): yii\web\Response->send()
#2 C:\OSPanel\domains\sofaYii.local\web\index.php(12): yii\base\Application->run()
#3 {main}
  • Вопрос задан
  • 164 просмотра
Решения вопроса 1
@AUser0
Чем больше знаю, тем лучше понимаю, как мало знаю.
Дотягивайтесь до $match['events'][0]['id'], и всё будет работать.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы