1

Estou tentando passar uma função escrita em javasript para o php,mas acho que errei na tradução de algum comando e não consigo achar o erro. Função em JavaScript:

<script>

    function dec(string)
        {// retorna a matris pura, descompactada
            var myArray = [];
            var str, str2, arr, arr2, lat, lng, f;
            var strings = string.split(" ");
            for(var i=0; i<strings.length; i++)
            {
                str = strings[i];
                str2 = '';
                arr = [];
                arr2 = [];
                for (var j=0; j<str.length; j++)
                {
                    switch (str.charAt(j))
                    {
                        case 'A': str2 += ',0'; break;
                        case 'B': str2 += ',1'; break;
                        case 'C': str2 += ',-1'; break;
                        case 'D': str2 += ',2'; break;
                        case 'E': str2 += ',-2'; break;
                        case 'F': str2 += ',3'; break;
                        case 'G': str2 += ',-3'; break;
                        case 'H': str2 += ',4'; break;
                        case 'I': str2 += ',-4'; break;
                        case 'J': str2 += ',5'; break;
                        case 'K': str2 += ',-5'; break;
                        case 'L': str2 += ',6'; break;
                        case 'M': str2 += ',-6'; break;
                        case 'N': str2 += ',7'; break;
                        case 'O': str2 += ',-7'; break;
                        case 'P': str2 += ',8'; break;
                        case 'Q': str2 += ',-8'; break;
                        case 'R': str2 += ',9'; break;
                        case 'S': str2 += ',-9'; break;
                        default: str2 += str.charAt(j); break;
                    }
                }
                arr = str2.split(",");
                f = arr.shift();
                lng = parseInt(arr[0])/f;
                lat = parseInt(arr[1])/f;
                arr2.push([lat, lng]);
                for (var j=2; j<arr.length; j+=2)

                {
                    lng += parseInt(arr[j])/f;
                    lat += parseInt(arr[j+1])/f;
                    arr2.push([lat, lng]);
                }
                myArray.push(arr2);
            }
            return myArray;
        }
    dec("1000I6575E3374BCBAACBABABABABBABBAABBBABBAABBABBDABAABBBABBAABBAABBABAABBBABBAABBBABBBBAABBAACBABCBABAABBABCBAACBCACBABAACBABAACBAAAACCAACCCACBCACACCACCCCCAACCCCCCACAACACACACACACACACACACCCACAACAACCCCCCCCCCACCACCCACCACCACACACBAACACACCAACACCAACACBAACACACCACCCACAACCACAACAACAACCACAACCACAACACBAACAAACACACCAACBCAAACACACACACACCAACACCAACACBAACACBAACBAACACACACACACCACAACACACACACCAACACCAACBAACACCAACCAACACACCCACACBAACBAACACACBAACACBAACBAACACBCBCBCACBAACACACBAACACACACACACACACACACACACACBCACACACACACCEACCEACACBAACACBAACBAACACAAACACBABCBAACBAABBBBABBBABABABABAABBABBBAABBBBBABBAABBBBBBBBABBBAABBBABBABAABBABABAABBAABBABBABBBBAABBBBAABBABABBABBABABBBABBBABAABBABABABBBABABABAABBABABABABABABABBBABABABCBABABAACBABBBABADABABABABABCBABABABCBABCBABCBABAACBABABAACBABABABABABABBACBABABBBABABABABAABBABABABABBBABABAABBAACBABABABAABBABAABCBABBABABAACBCBAABCAABBABAABABABBABAABBABABCBABABABAACBABAAAABBABBACBAACBABAABCAABBAABBABAABBABAACACBABAACCCCAACBABAACACBCBAABABBAACACBACCCABCBAACCACAACACCAACACBAACBABAABBAACBAACBAABABBAABABBABCBABAABBAABBAABBABABABAACBABABAABABBAABCAABABABBAABAAAABAACBAABAAABABBAABBAACACBAACACBAACACBAACBAACCAACBAACACACBAACBAACACBAACBCACBAACBAACACBAACBAACACACBAACACBAACBAACACBAACBAACACACACCAACACACACACCACACACBCACACAACCACCACBAACCAACCACACACACAACCACAACCAACACACCACACCAAACBABAACCAACCAACCACAACCAACCAACCAACCAACCBCACAACAAACBAACACACACACACBAACBCACBABAACBCACBAACACACCCCAECCACACAAEBCBAACACBACCACBAACAAACACBAACBABCBABAACBABABCBABABABAAAACACECCCACAAACCABCCCBAACBABAACACBABABAACACCACCCACACCCAACACBABCBAACACBAACACBCACBAACACBAACCAABCAABCAACCAACCAACCCACACACCAACACACBAACACCAACCACACACACACCCCCAABCACACACAACCCCCCAACAAACACBABCBAACBCACACACCAACCCCAACACACCAACCAACCAACCACCCACACACAACACCAACACBCACACACACCAACCACACCCCCACAACACACCAACACCACAACCACACACAACACACCACACAABABABABCACBABCAABCACACBCCCAACACACBAACCAACCACACACBCCCACACACACCCCCACACACACBCACACAABCACAABCACACACAACCACAABCACAABCAABCACACAABCAACCBACCACACACACACAABABCAABABCAABABCAABAAABAAABCAABABABABCAABCCABCACBCACACACAABCACAACCACACAACCAABCACCCACAABCAACCACAABCACACAACCACACCCACACAABCACBCAABCAABCAABABCAABCAABCACACACBABCACBCAABCACACACACACACACACACAACCBCACACACAABCACBCAABCACAABCACBCAABCAABCAABCACACACACAACCAACCAACCCACCACCCACACBCACBCBCACBCAABCACBCAABCAABCACAABCACBCBCACACAABCACAACACACACACACCAACACACAECCACAEAECEACACACCCAEACACBAACBAACACCCACACCACAACCAACACBCACAEACBACCACACCAACACCACCCAACCAACCACAACCACAACCACAACCAACCACACACAACCACAACCAACCACACACAACCACCCAACCACACAACCACAABCAABCAABCCEAACCCCAACCACBCAABCAACACCCACACACACACACACCAACACCACAACCAACACACACACBAACACCCCAACCAACCAACBAACACACCCACCCCCACBABABAACACBAACACACACBABABCACACBAACBAACBCBBBAACACACACBAABBCACBABABABAACBAACACBAACCAACCAACCAACCACAACCACACCCACACACCCCCCCCCCCCCCCCCAACCAACCACAACCAECCAECCAEACCCACCCABKBAAEBEACDSAEAEBEBCBEDELOBEFGDGJKACBCBCACACAGAC2ACACACACAKACACACACCCAEAECAACCCCCCAACCAACEECCCCCCACACACACACCEAGAGBEBOBEBCDCDADEDCDCDEDCACAEACACACACACACBCACACACACACACCAACACACACAECAACACACACACBCACBCCCBEBCCCBCACACACBAACACACACBAACHBEECCCAACACBAACACACACDAACBAACACCAACACBCACACACACCACAACBCBCACCACACAACACCAACCAAAEACAACACACBCACACBABABCDABBDAACBAACCCACCAACBCBECCBCCAACACCACAACCAACDEBAACBAACACACACCAACAAACCACAACBABACCBCACCCCACAACAACCACACACCAABABCACBCAACCACACCACCAACCACACACACAACCACACAACCCABCAACAACAACCAACCACAACCACAACBAACACACBCACBAACACACACACBAACBAACBABAACCAACCACACACCACCCCACBCAACCAACACCAACCACACAACCACACACCCACCCAAACAABCBABCBABCACAABCBABCACBCACAABABCBCBCACACACACACACCCACACACACACACACACBCACAABCAABCBABABCAABCACACCACCACCCACBCACACCACCAACCACCCAACCAACCACACCCACCCAABCACACACACCACCACCCACAACCAACCACACACACBCAABABCACACCCACACACACCCACACACACACAABCACBCAABCACACACACACACAACACCACACACACACAACBAACCACAAACACACACCCAACACCAACCCCCACCACACCACACCACACACAABCAACCAACCCCACACAABABCACAABABCAABBAABBABBBAABBABAABBAABABABBBABBBCBBAABBBABBAABBABAABABBAABBAABABABBAABBAABCAABABBABAABBAABBAABABABABCACAACCAABCAABCBCBCAABCAABCAABBAABABABCBCACBCACCCAABCACACAABCBCBABCAABABBAABCBABBBABCACACACACBCACAABCAABCACAABBAABCAABCAABCBCACBCACAACCAACCACACACBCBABCAABCACAABCACACACACACCCACBABABABABCBABABABABABCBABCBABABABABCBABABBACBCAABBAABABCAABABBAABCAABBACBBAABAAABABBAABBAABABBAABBAABABBBABBAABABABBAABCAABBACBABCAAACAABABABABAABABCBBACBABAACBAACACACACBAACBABAABBABABCBABADABABCBABAABBABADADABABBBABAABBJADABAFANAPAB0ABCAABCAABCBABCABBABCAABBAABABABABCAABABBABABABAACBABCBABBACBABBBABAACBAABBABABAABABBAABABABABABABABCACCABCAABBABAABBAABABABABABABCACBCAABCAABCAABCAABCAABCACAABCAABCACAABCACAABCACBCAABCACAABCACACACACAABCACAABCACACACACACACACACAABCACACAABCAABABABBAABAAABBAABCAABBAAABAABBAABBABAABABABABBAABBAABBBBAABABBABAABBAABCAAAABAABAAABBABCACAABBACBABAAABCBABABABBBABABBABBDBDABBBABABBABBBBBABBABBBABABAABBBBAABBDABBDABABABABCBCACBCACCCACAABCAABCAABCACAABCCACCAABCAABCAABCACAABCACBCBCAABCBBBABCACAABCACACBCAABABABABCBABCAABABCBABBAABDBBAABABBAABBBABBBCAABBAABABABCAABBAABABCAABABABABABAAABBAABABABBAABAAABCAABAAABCAABCACACACBCACACBCAABBABABAABBAABABCAABCBABABCBABCAABCAABBACBBAABABBAABABABABABBBABABBAABBAABABBAABABBAABABABABABABBAABABAAABABABABBAABABABABBAABABABABAAABCAABABBABBBBBAABABABBAABBBBABAABABBABABABAABBAABBABAABAAABBAABABABBAABBABAABBABAABBABAABBAABBAABABBAABBAABBAABBAABBBBAABBAABABABBAABBAABBABAABBAABBAACBAABBABAABABABABBBBAABBBCACAABABCACAABCACACBCACAABCAABABCBABCAACCAACCAACCAACCACACACCCACACACACACAACCCACCACAEBCCACCACACACACACAACCACAACCACACBCACCCACACAABCACACAACACCCCACACACCCACACAAAABCBABABAAABABCAABBAABCAABABABBAABABBBCAABBAABABBBABBAABABCAABCAABABABBABABABABBAABABABABAACBBBABAABABBABAABBAABABBABBBCBBBAABABBAABBABABCBAABBBBBABBABABABABBBABAABBAABABABABBABABDBAAABAACBABAABABABBAABABBABBABABBAABBAABABBAABABCAABABBAABCAABCBABABABBAABABABABABABABCAABBAABABABABABABDBBDBBBABABABABABABAABBAABABBDCACAACCACACAABCAABABABCACAABEACAABABAAABCACAABABCBAAABCACBABCAABABBAABBAABABBAABBAABBABABAABABABBAABAAABCAABCACAABCACACACACAABCACAABCAABABABCAABABCAABCBABABABABADABABABCAABCACAABCAABCAABABCBABABBAABABABBAABBABAABABBBABBABAABCACAACCACAACCAACACCCCCACCACACACACAABCAACCAACCACACACAABCAABCAABCACAABCAAACACAACCACAACCCACBAACCAACACACCACAACCACBBBABCAABCBCBCBCBABCAABABABABABABABCAABCAABABCAABABABABABABABCAABBBABCAABCACAABABABABABCAABCAABCAABCAABABABCACACBCAABCAABCAABCBABABABABBAABBABAABABABABABCAABCAABABCACAABCAABCBABBAABBAABCAABCBBAABBAABBAABBAACBAABBAABBABAAABAABBCBABABAABBABABCBABAABBAABAABAABBABABAABCAABBABAACBAACBAACBAACACCAACCAACBAACBAABBAACBABACBABBAABBABABABAACBAACAAAABABAACAAACBABAACBABBBABAABABABCAABABBABAABBABABCBABABACBBBBABABABABAAAABABAAABBAABCAABBAABABABABBAACBAABABBABAABBAABBAACBABCBAABBAACBAABBABCBABABAACACBAACBABABAABBAAABAACBAABBCABBABAAABABAACBBBABABABABBBAACBAACACBAACBAACBAACBABABAACBABABABABAACBAACBABCACACACACACACBAACBCBCBABABABABABBACBAACACBCACACACACACACBAAABAACBABABABABCABBABAACACACACACACACBABABABABABABBBABCBCBCBCBABAABBBABABABABABABBABBBAABBABABAABBABBACBADEBCBABABABABAACBAACBCBCACBABCBABABCBCACBCACBAACBABABBBABABBBABABABABBBABABABABADBBABCBABAACBABABBBAABABBABABDBBBABADABAABBAABABCBCBABBABABAACBABADABABABAABBACBCBABABABABBABAABBACDABABBBBBABBBABBAABBAABBBBAABBABABBBABBBAABABABCBCAABABABBABBBABAABBABBBABABABBBBBBABBABABAABBAABBAABBAABBABAABABBBBABABABABA");


    </script>

Função em PHP:

Descompacta('1000I6575E3374BCBAACBABABABABBABBAABBBABBAABBABBDABAABBBABBAABBAABBABAABBBABBAABBBABBBBAABBAACBABCBABAABBABCBAACBCACBABAACBABAACBAAAACCAACCCACBCACACCACCCCCAACCCCCCACAACACACACACACACACACACCCACAACAACCCCCCCCCCACCACCCACCACCACACACBAACACACCAACACCAACACBAACACACCACCCACAACCACAACAACAACCACAACCACAACACBAACAAACACACCAACBCAAACACACACACACCAACACCAACACBAACACBAACBAACACACACACACCACAACACACACACCAACACCAACBAACACCAACCAACACACCCACACBAACBAACACACBAACACBAACBAACACBCBCBCACBAACACACBAACACACACACACACACACACACACACBCACACACACACCEACCEACACBAACACBAACBAACACAAACACBABCBAACBAABBBBABBBABABABABAABBABBBAABBBBBABBAABBBBBBBBABBBAABBBABBABAABBABABAABBAABBABBABBBBAABBBBAABBABABBABBABABBBABBBABAABBABABABBBABABABAABBABABABABABABABBBABABABCBABABAACBABBBABADABABABABABCBABABABCBABCBABCBABAACBABABAACBABABABABABABBACBABABBBABABABABAABBABABABABBBABABAABBAACBABABABAABBABAABCBABBABABAACBCBAABCAABBABAABABABBABAABBABABCBABABABAACBABAAAABBABBACBAACBABAABCAABBAABBABAABBABAACACBABAACCCCAACBABAACACBCBAABABBAACACBACCCABCBAACCACAACACCAACACBAACBABAABBAACBAACBAABABBAABABBABCBABAABBAABBAABBABABABAACBABABAABABBAABCAABABABBAABAAAABAACBAABAAABABBAABBAACACBAACACBAACACBAACBAACCAACBAACACACBAACBAACACBAACBCACBAACBAACACBAACBAACACACBAACACBAACBAACACBAACBAACACACACCAACACACACACCACACACBCACACAACCACCACBAACCAACCACACACACAACCACAACCAACACACCACACCAAACBABAACCAACCAACCACAACCAACCAACCAACCAACCBCACAACAAACBAACACACACACACBAACBCACBABAACBCACBAACACACCCCAECCACACAAEBCBAACACBACCACBAACAAACACBAACBABCBABAACBABABCBABABABAAAACACECCCACAAACCABCCCBAACBABAACACBABABAACACCACCCACACCCAACACBABCBAACACBAACACBCACBAACACBAACCAABCAABCAACCAACCAACCCACACACCAACACACBAACACCAACCACACACACACCCCCAABCACACACAACCCCCCAACAAACACBABCBAACBCACACACCAACCCCAACACACCAACCAACCAACCACCCACACACAACACCAACACBCACACACACCAACCACACCCCCACAACACACCAACACCACAACCACACACAACACACCACACAABABABABCACBABCAABCACACBCCCAACACACBAACCAACCACACACBCCCACACACACCCCCACACACACBCACACAABCACAABCACACACAACCACAABCACAABCAABCACACAABCAACCBACCACACACACACAABABCAABABCAABABCAABAAABAAABCAABABABABCAABCCABCACBCACACACAABCACAACCACACAACCAABCACCCACAABCAACCACAABCACACAACCACACCCACACAABCACBCAABCAABCAABABCAABCAABCACACACBABCACBCAABCACACACACACACACACACAACCBCACACACAABCACBCAABCACAABCACBCAABCAABCAABCACACACACAACCAACCAACCCACCACCCACACBCACBCBCACBCAABCACBCAABCAABCACAABCACBCBCACACAABCACAACACACACACACCAACACACAECCACAEAECEACACACCCAEACACBAACBAACACCCACACCACAACCAACACBCACAEACBACCACACCAACACCACCCAACCAACCACAACCACAACCACAACCAACCACACACAACCACAACCAACCACACACAACCACCCAACCACACAACCACAABCAABCAABCCEAACCCCAACCACBCAABCAACACCCACACACACACACACCAACACCACAACCAACACACACACBAACACCCCAACCAACCAACBAACACACCCACCCCCACBABABAACACBAACACACACBABABCACACBAACBAACBCBBBAACACACACBAABBCACBABABABAACBAACACBAACCAACCAACCAACCACAACCACACCCACACACCCCCCCCCCCCCCCCCAACCAACCACAACCAECCAECCAEACCCACCCABKBAAEBEACDSAEAEBEBCBEDELOBEFGDGJKACBCBCACACAGAC2ACACACACAKACACACACCCAEAECAACCCCCCAACCAACEECCCCCCACACACACACCEAGAGBEBOBEBCDCDADEDCDCDEDCACAEACACACACACACBCACACACACACACCAACACACACAECAACACACACACBCACBCCCBEBCCCBCACACACBAACACACACBAACHBEECCCAACACBAACACACACDAACBAACACCAACACBCACACACACCACAACBCBCACCACACAACACCAACCAAAEACAACACACBCACACBABABCDABBDAACBAACCCACCAACBCBECCBCCAACACCACAACCAACDEBAACBAACACACACCAACAAACCACAACBABACCBCACCCCACAACAACCACACACCAABABCACBCAACCACACCACCAACCACACACACAACCACACAACCCABCAACAACAACCAACCACAACCACAACBAACACACBCACBAACACACACACBAACBAACBABAACCAACCACACACCACCCCACBCAACCAACACCAACCACACAACCACACACCCACCCAAACAABCBABCBABCACAABCBABCACBCACAABABCBCBCACACACACACACCCACACACACACACACACBCACAABCAABCBABABCAABCACACCACCACCCACBCACACCACCAACCACCCAACCAACCACACCCACCCAABCACACACACCACCACCCACAACCAACCACACACACBCAABABCACACCCACACACACCCACACACACACAABCACBCAABCACACACACACACAACACCACACACACACAACBAACCACAAACACACACCCAACACCAACCCCCACCACACCACACCACACACAABCAACCAACCCCACACAABABCACAABABCAABBAABBABBBAABBABAABBAABABABBBABBBCBBAABBBABBAABBABAABABBAABBAABABABBAABBAABCAABABBABAABBAABBAABABABABCACAACCAABCAABCBCBCAABCAABCAABBAABABABCBCACBCACCCAABCACACAABCBCBABCAABABBAABCBABBBABCACACACACBCACAABCAABCACAABBAABCAABCAABCBCACBCACAACCAACCACACACBCBABCAABCACAABCACACACACACCCACBABABABABCBABABABABABCBABCBABABABABCBABABBACBCAABBAABABCAABABBAABCAABBACBBAABAAABABBAABBAABABBAABBAABABBBABBAABABABBAABCAABBACBABCAAACAABABABABAABABCBBACBABAACBAACACACACBAACBABAABBABABCBABADABABCBABAABBABADADABABBBABAABBJADABAFANAPAB0ABCAABCAABCBABCABBABCAABBAABABABABCAABABBABABABAACBABCBABBACBABBBABAACBAABBABABAABABBAABABABABABABABCACCABCAABBABAABBAABABABABABABCACBCAABCAABCAABCAABCAABCACAABCAABCACAABCACAABCACBCAABCACAABCACACACACAABCACAABCACACACACACACACACAABCACACAABCAABABABBAABAAABBAABCAABBAAABAABBAABBABAABABABABBAABBAABBBBAABABBABAABBAABCAAAABAABAAABBABCACAABBACBABAAABCBABABABBBABABBABBDBDABBBABABBABBBBBABBABBBABABAABBBBAABBDABBDABABABABCBCACBCACCCACAABCAABCAABCACAABCCACCAABCAABCAABCACAABCACBCBCAABCBBBABCACAABCACACBCAABABABABCBABCAABABCBABBAABDBBAABABBAABBBABBBCAABBAABABABCAABBAABABCAABABABABABAAABBAABABABBAABAAABCAABAAABCAABCACACACBCACACBCAABBABABAABBAABABCAABCBABABCBABCAABCAABBACBBAABABBAABABABABABBBABABBAABBAABABBAABABBAABABABABABABBAABABAAABABABABBAABABABABBAABABABABAAABCAABABBABBBBBAABABABBAABBBBABAABABBABABABAABBAABBABAABAAABBAABABABBAABBABAABBABAABBABAABBAABBAABABBAABBAABBAABBAABBBBAABBAABABABBAABBAABBABAABBAABBAACBAABBABAABABABABBBBAABBBCACAABABCACAABCACACBCACAABCAABABCBABCAACCAACCAACCAACCACACACCCACACACACACAACCCACCACAEBCCACCACACACACACAACCACAACCACACBCACCCACACAABCACACAACACCCCACACACCCACACAAAABCBABABAAABABCAABBAABCAABABABBAABABBBCAABBAABABBBABBAABABCAABCAABABABBABABABABBAABABABABAACBBBABAABABBABAABBAABABBABBBCBBBAABABBAABBABABCBAABBBBBABBABABABABBBABAABBAABABABABBABABDBAAABAACBABAABABABBAABABBABBABABBAABBAABABBAABABCAABABBAABCAABCBABABABBAABABABABABABABCAABBAABABABABABABDBBDBBBABABABABABABAABBAABABBDCACAACCACACAABCAABABABCACAABEACAABABAAABCACAABABCBAAABCACBABCAABABBAABBAABABBAABBAABBABABAABABABBAABAAABCAABCACAABCACACACACAABCACAABCAABABABCAABABCAABCBABABABABADABABABCAABCACAABCAABCAABABCBABABBAABABABBAABBABAABABBBABBABAABCACAACCACAACCAACACCCCCACCACACACACAABCAACCAACCACACACAABCAABCAABCACAABCAAACACAACCACAACCCACBAACCAACACACCACAACCACBBBABCAABCBCBCBCBABCAABABABABABABABCAABCAABABCAABABABABABABABCAABBBABCAABCACAABABABABABCAABCAABCAABCAABABABCACACBCAABCAABCAABCBABABABABBAABBABAABABABABABCAABCAABABCACAABCAABCBABBAABBAABCAABCBBAABBAABBAABBAACBAABBAABBABAAABAABBCBABABAABBABABCBABAABBAABAABAABBABABAABCAABBABAACBAACBAACBAACACCAACCAACBAACBAABBAACBABACBABBAABBABABABAACBAACAAAABABAACAAACBABAACBABBBABAABABABCAABABBABAABBABABCBABABACBBBBABABABABAAAABABAAABBAABCAABBAABABABABBAACBAABABBABAABBAABBAACBABCBAABBAACBAABBABCBABABAACACBAACBABABAABBAAABAACBAABBCABBABAAABABAACBBBABABABABBBAACBAACACBAACBAACBAACBABABAACBABABABABAACBAACBABCACACACACACACBAACBCBCBABABABABABBACBAACACBCACACACACACACBAAABAACBABABABABCABBABAACACACACACACACBABABABABABABBBABCBCBCBCBABAABBBABABABABABABBABBBAABBABABAABBABBACBADEBCBABABABABAACBAACBCBCACBABCBABABCBCACBCACBAACBABABBBABABBBABABABABBBABABABABADBBABCBABAACBABABBBAABABBABABDBBBABADABAABBAABABCBCBABBABABAACBABADABABABAABBACBCBABABABABBABAABBACDABABBBBBABBBABBAABBAABBBBAABBABABBBABBBAABABABCBCAABABABBABBBABAABBABBBABABABBBBBBABBABABAABBAABBAABBAABBABAABABBBBABABABABA');
function Descompacta($string){
        $myArray = [];
        $str; 
        $str2; 
        $arr;
        $arr2;
        $lat;
        $lng; 
        $f;
        $strings = split(" ",$string);
        for($i=0; $i<count($strings); $i++)
        {
            $str = $strings[$i];
            $str2 = '';
            $arr = [];
            $arr2 = [];
            for ($j=0; $j<strlen($str); $j++)
            {
                switch (substr($str,$j))
                {
                    case 'A': $str2 += ',0'; break;
                    case 'B': $str2 += ',1'; break;
                    case 'C': $str2 += ',-1'; break;
                    case 'D': $str2 += ',2'; break;
                    case 'E': $str2 += ',-2'; break;
                    case 'F': $str2 += ',3'; break;
                    case 'G': $str2 += ',-3'; break;
                    case 'H': $str2 += ',4'; break;
                    case 'I': $str2 += ',-4'; break;
                    case 'J': $str2 += ',5'; break;
                    case 'K': $str2 += ',-5'; break;
                    case 'L': $str2 += ',6'; break;
                    case 'M': $str2 += ',-6'; break;
                    case 'N': $str2 += ',7'; break;
                    case 'O': $str2 += ',-7'; break;
                    case 'P': $str2 += ',8'; break;
                    case 'Q': $str2 += ',-8'; break;
                    case 'R': $str2 += ',9'; break;
                    case 'S': $str2 += ',-9'; break;
                    default: $str2 += substr($str,$j); break;
                }
            }
            $arr = split(",",$str2);
            $f = array_shift($arr);
            $lng = $arr[0]/$f;
            $lat = $arr[1]/$f;
            array_push($arr2,[$lat, $lng]);

            for ($j=2; $j<count($arr); $j+=2)

            {
                $lng += $arr[$j]/$f;
                $lat += $arr[$j+1]/$f;
                array_push($arr2,[$lat, $lng]);
            }
            array_push($myArray,$arr2);
        }
        }

Os erros começam aqui:

$arr = split(",",$str2);

Alguém percebeu onde está o erro?

1 Resposta 1

3

1º Problema

O problema que indicaste é causado pelo uso da função errada para o efeito desejado.

Se pretendes dividir uma string em array usando como caractere separador uma virgula, precisas de utilizar a função explode():

$arr = explode(",", $str2);

A função split() faz o mesmo que a função explode(), mas a forma como operam é diferente:

explode() - Divide a string em array usando uma string.

slit() - Divide a string em array usando uma expressão regular.

2º Problema

A função substr() do PHP, se não receber os 3 parâmetros não vai devolver apenas um caractere como pretendes que aconteça. Onde tens:

substr($str,$j) // tudo depois da posição $j

Tens que colocar:

substr($str, $j, 1) // um caractere após a posição $j

3º Problema

A concatenação em PHP é realizada com o caractere ., no teu switch() está a utilizar o caractere +, ou seja, onde tens:

switch (substr($str,$j)) {
  case 'A': $str2 += ',0'; break;
  case 'B': $str2 += ',1'; break;
  case 'C': $str2 += ',-1'; break;
  case 'D': $str2 += ',2'; break;
  case 'E': $str2 += ',-2'; break;
  case 'F': $str2 += ',3'; break;
  case 'G': $str2 += ',-3'; break;
  case 'H': $str2 += ',4'; break;
  case 'I': $str2 += ',-4'; break;
  case 'J': $str2 += ',5'; break;
  case 'K': $str2 += ',-5'; break;
  case 'L': $str2 += ',6'; break;
  case 'M': $str2 += ',-6'; break;
  case 'N': $str2 += ',7'; break;
  case 'O': $str2 += ',-7'; break;
  case 'P': $str2 += ',8'; break;
  case 'Q': $str2 += ',-8'; break;
  case 'R': $str2 += ',9'; break;
  case 'S': $str2 += ',-9'; break;
  default: $str2 += substr($str,$j); break;
}

Deverás ter:

switch (substr($str, $j, 1)) {
  case 'A': $str2 .= ',0'; break;
  case 'B': $str2 .= ',1'; break;
  case 'C': $str2 .= ',-1'; break;
  case 'D': $str2 .= ',2'; break;
  case 'E': $str2 .= ',-2'; break;
  case 'F': $str2 .= ',3'; break;
  case 'G': $str2 .= ',-3'; break;
  case 'H': $str2 .= ',4'; break;
  case 'I': $str2 .= ',-4'; break;
  case 'J': $str2 .= ',5'; break;
  case 'K': $str2 .= ',-5'; break;
  case 'L': $str2 .= ',6'; break;
  case 'M': $str2 .= ',-6'; break;
  case 'N': $str2 .= ',7'; break;
  case 'O': $str2 .= ',-7'; break;
  case 'P': $str2 .= ',8'; break;
  case 'Q': $str2 .= ',-8'; break;
  case 'R': $str2 .= ',9'; break;
  case 'S': $str2 .= ',-9'; break;
  default: $str2 .= substr($str, $j, 1); break;
}

4º Problema

A tua função não está a devolver nada, ou seja, a mesma é chamada, realiza o seu trabalho e depois "deita fora" o que esteve a fazer. No final da mesma deverás fazer uso do return para devolver a variável $myArray:

function Descompacta($string) {

  // ...

  return $myArray;
}

5º Problema

Antes da divisão dos valores para as variáveis $lng e $lat, em JavaScript, está a ser extraído o valor inteiro para utilizar na divisão. No PHP não estás a agir dessa forma.

Para este efeito, podes fazer uso da função intval() que te vai devolver o valor inteiro de uma variável:

$lng = $arr[0]/$f;
$lat = $arr[1]/$f;

Vai passar para:

$lng = intval($arr[0])/$f;
$lat = intval($arr[1])/$f;

Exemplo no Ideone

Usei uma string de entrada mais pequena porque o Ideone não disponibiliza memória suficiente para executar o script com o tamanho da tua string original:

function Descompacta($string) {

    $myArray = [];
    $str; 
    $str2; 
    $arr;
    $arr2;
    $lat;
    $lng; 
    $f;
    $strings = explode(" ",$string);

    for ($i=0; $i<count($strings); $i++) {

        $str = $strings[$i];
        $str2 = '';
        $arr = [];
        $arr2 = [];

        for ($j=0; $j<strlen($str); $j++) {

            switch (substr($str, $j, 1)) {

                case 'A': $str2 .= ',0';    break;
                case 'B': $str2 .= ',1';    break;
                case 'C': $str2 .= ',-1';   break;
                case 'D': $str2 .= ',2';    break;
                case 'E': $str2 .= ',-2';   break;
                case 'F': $str2 .= ',3';    break;
                case 'G': $str2 .= ',-3';   break;
                case 'H': $str2 .= ',4';    break;
                case 'I': $str2 .= ',-4';   break;
                case 'J': $str2 .= ',5';    break;
                case 'K': $str2 .= ',-5';   break;
                case 'L': $str2 .= ',6';    break;
                case 'M': $str2 .= ',-6';   break;
                case 'N': $str2 .= ',7';    break;
                case 'O': $str2 .= ',-7';   break;
                case 'P': $str2 .= ',8';    break;
                case 'Q': $str2 .= ',-8';   break;
                case 'R': $str2 .= ',9';    break;
                case 'S': $str2 .= ',-9';   break;
                default: $str2 .= substr($str, $j, 1);
            }
        }

        $arr = explode(",", $str2);
        $f = array_shift($arr);
        $lng = intval($arr[0])/$f;
        $lat = intval($arr[1])/$f;
        array_push($arr2,[$lat, $lng]);

        for ($j=2; $j<count($arr); $j+=2) {

            $lng += intval($arr[$j])/$f;
            $lat += intval($arr[$j+1])/$f;
            array_push($arr2,[$lat, $lng]);
        }

        array_push($myArray,$arr2);
    }

    return $myArray;
}

$output = Descompacta('1000I6575E3374BCBAACBABABABABBABBAABBBABBAABBABBDABAABBBABBAABBAABBABAABBBABBAABBBABBBBAABBAACBABCBABAABBABCBAACBCACB');

var_dump($output);
5
  • ,entendi,mas eu acho que o erro está quando sai do switchcase pois se eu der print_r no $str2,ele sai como "INF" Commented 4/04/2015 às 0:38
  • Não foi o que referias na pergunta, não estive a analisar tudo. Mas no teu switch() estás a concatenar com += mas em PHP tens que usar .= :)
    – Zuul
    Commented 4/04/2015 às 0:48
  • @RodolfoOliveira Estive a rever a função, resolvi mais problemas que encontrei e montei um exemplo no Ideone. Lê a resposta para saberes onde encontrei problemas e porque é que eles aconteceram.
    – Zuul
    Commented 4/04/2015 às 1:53
  • 1
    Parece que você está certo, mas notei que nos exemplos faltou o intval (para ser equivalente ao parseInt), não? Eu não testei o código e realmente não sei como funciona, mas acredito que isto seja parte da importante.
    – Syzoth
    Commented 4/04/2015 às 3:25
  • @GuilhermeNascimento Obrigado, não tinha visto esse detalhe. Não entendi ainda se é requerido ou se já vinha a mais do original em JS, mas está lá :)
    – Zuul
    Commented 4/04/2015 às 13:24

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .