src/Ridvanbaluyos/Mmda/MMDA.php
final private function parseTrafficData($xml)
    {
        $traffic = [];

        foreach ($xml->channel->item as $item) {
            $item = get_object_vars($item);
            $title = $item['title'];
            $description = $item['description'];
            $pubDate = $item['pubDate'];

            $highway = explode('-', $title, 2)[0];
            $segment = substr(explode('-', $title, 2)[1], 0, -3);
            $direction = substr(explode('-', $title, 2)[1], -2);

            if (empty($traffic[$highway])) $traffic[$highway] = [];
            if (empty($traffic[$highway][$segment])) $traffic[$highway][$segment] = [];

            $traffic[$highway][$segment][$direction] = $description;
            $traffic[$highway][$segment]['pubDate'] = $pubDate;
        }

        return $traffic;
    }
final private function parseTrafficData($xml)
    {
        $traffic = [];

        foreach ($xml->channel->item as $item) {
            $item = get_object_vars($item);
            $title = $item['title'];
            $description = $item['description'];
            $pubDate = $item['pubDate'];

            $highway = explode('-', $title, 2)[0];
            $segment = substr(explode('-', $title, 2)[1], 0, -3);
            $direction = substr(explode('-', $title, 2)[1], -2);

            if (empty($traffic[$highway])) $traffic[$highway] = [];
            if (empty($traffic[$highway][$segment])) $traffic[$highway][$segment] = [];

            $traffic[$highway][$segment][$direction] = $description;
            $traffic[$highway][$segment]['pubDate'] = $pubDate;
        }

        return $traffic;
    }
final private function parseTrafficData ( $ xml ) { $ traffic = [ ] ; foreach ( $ xml -> channel -> item as $ item ) { $ item = get_object_vars ( $ item ) ; $ title = $ item [ 'title' ] ; $ description = $ item [ 'description' ] ; $ pubDate = $ item [ 'pubDate' ] ; $ highway = explode ( '-' , $ title , 2 ) [ 0 ] ; $ segment = substr ( explode ( '-' , $ title , 2 ) [ 1 ] , 0 , - 3 ) ; $ direction = substr ( explode ( '-' , $ title , 2 ) [ 1 ] , - 2 ) ; if ( empty ( $ traffic [ $ highway ] ) ) $ traffic [ $ highway ] = [ ] ; if ( empty ( $ traffic [ $ highway ] [ $ segment ] ) ) $ traffic [ $ highway ] [ $ segment ] = [ ] ; $ traffic [ $ highway ] [ $ segment ] [ $ direction ] = $ description ; $ traffic [ $ highway ] [ $ segment ] [ 'pubDate' ] = $ pubDate ; } return $ traffic ; }
This function parses the XML response from the MMDA Traffic API into JSON.

@param $xml
@return array
This function parses the XML response from the MMDA Traffic API into JSON .