Convert function from JS to PHP
<p>I have a function in javascript and it works just fine, but now I need same function in PHP and it has very strange behavior. It seems to me that functions are identical, still I missed something and cannot find it.</p>

<p>borders, neighbors are pre-defined arrays and base is predefined string.</p>

<p><strong>Java Script</strong></p>

<pre><code>function calculateAdjacent(sourceBase, direction) {
    sourceBase = sourceBase.toLowerCase();
    var lastChar = sourceBase.charAt(sourceBase.length-1);
    var type = (sourceBase.length % 2) ? 'odd' : 'even';
    var base = sourceBase.substring(0,sourceBase.length-1);
    if (BORDERS[direction][type].indexOf(lastChar)!=-1)
    {
        base = calculateAdjacent(base, direction);
    }
    return base + TABLE[NEIGHBORS[direction][type].indexOf(lastChar)];
}
</code></pre>

<p><strong>PHP</strong></p>

<p>($table, $neighbors, $borders are defined, they take a lot of space but I can but them in.)</p>

<pre><code>function calculateAdjacent($sourceBase, $direction)
{
    $sourceBase = strtolower($sourceBase);
    $lastChar = $sourceBase[strlen($sourceBase) - 1];
    if (strlen($sourceBase) % 2)
    {
        $type = "odd";
    }
    else
    {
        $type = "even";
    }
    $base = substr($sourceBase, 0, strlen($sourceBase) - 1);
    if (strpos($borders[$direction][$type], $lastChar) === false)
    {
        $base = calculateAdjacent($base, $direction);
    }
    // Problem in this line, need to fix '+' to '.'
    return $base + $table[strpos($neighbors[$direction][$type], $lastChar)];
}
</code></pre>
