H
H
Historian1112019-06-15 08:09:56
Yii
Historian111, 2019-06-15 08:09:56

How to reach the key in the array, after forich (gives an error)?

Good morning! There was a problem, for me very not clear.

Foric
if (is_array($data)) {
                foreach ($data['tournamentInfo']['featuredMatches']['tournaments'] as $match) {

                    echo '<pre>';
                    print_r($match);
                    echo '</pre>';
                }
            }
iterate over the resulting array.
I get this
array

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
                )

        )

Now I need to reach out, let's say , but it gives out$match['events']['id']
mistake
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}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AUser0, 2019-06-15
@Historian111

Reach for $match['events'][0]['id'] and everything will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question