Transform a function from JavaScript to PHP

1

I'm trying to pass a function written in javasript to php, but I think I made a mistake in the translation of some command and I can not find the error. Function in 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>

Function in 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);
        }
        }

The errors start here:

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

Has anyone noticed where the error is?

    
asked by anonymous 04.04.2015 / 01:22

1 answer

3

1st Problem

The problem you indicated is caused by using the wrong function for the desired effect.

If you want to split a string into array using a comma separator character, you need to use the explode() :

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

The split() function does the same as the explode() , but the way they operate is different:

explode() - Splits the string into array using a regular expression.

2nd Problem

The slit() function of PHP, if you do not receive the 3 parameters will not return only one character as you want it to happen. Where you are:

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

You have to put:

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

3rd Problem

The concatenation in PHP is performed with the character substr() , in your . is using the character switch() , ie where you have:

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;
}

You should have:

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;
}

4th Problem

Your function is not returning anything, that is, it is called, does its work and then "throws away" what it has been doing. At the end of it you should use + to return the variable return :

function Descompacta($string) {

  // ...

  return $myArray;
}

5th Problem

Before splitting the values for the $myArray and $lng variables into JavaScript, the integer value to be used in the split is being extracted. In PHP you're not acting that way.

For this purpose, you can use the $lat function that will return the integer value of a variable:

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

Go to:

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

Example on Ideone

I used a smaller input string because Ideone does not provide enough memory to run script with the size of your original string :

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);
    
04.04.2015 / 01:47