PHP recursive function return value

情到浓时终转凉″ 提交于 2019-11-30 13:02:09

You're not returning the text properly e.g.

    } else {
        echo 'else 1<br />';
        return $str;   <---nothing in the 'parent' caller catches this, so it's lost
    }

Anywhere you do recursion and need to return a value, you must capture/return the recursive call itself:

    return check_length(substr($str, 0, -1), $max, $size, true);

or

    $newstr = check_length(...);
    return $newstr;

Return the result of your recursive function call ;)

return check_length(substr($str, 0, -1), $max, $size, true);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!