<?php
    $urlbase = $_SERVER['SERVER_NAME'].$_SERVER ['REQUEST_URI'];
    $parts = parse_url($urlbase);
    parse_str($parts['query'], $query);
    $_GET = $query;

    // Recupera opções
    $xml = simplexml_load_file('http://www.sysfbet.com.br/cdn/mercados.xml');
    $mercados = array();

    foreach ($xml as $mercado) {
        $i = 0;

        if(isset($_GET["choices"]) && $_GET["choices"] == 'false'){
            array_push($mercados, (string)$mercado->attributes()->name);
            $i++;
        } else {
            foreach ($mercado as $opcao) {
                $mercados[(string)$mercado->attributes()->name][$i] = (string)$opcao->attributes()->name;
                $i++;
            }
        }
    }

    echo json_encode($mercados);
?>