/* 循环去除字符串左边的0 */ function removeLeftZero($str){ if($str['0'] == '0'){ $str = substr($str, '1'); removeLeftZero($str); }else{ return $str; } }
这样运行之后若是是递归是不会有返回值的,递归后即便知足else条件也不会有返回值,应该改成函数
/* 循环去除字符串左边的0 */ function removeLeftZero($str){ if($str['0'] == '0'){ $str = substr($str, '1'); return removeLeftZero($str); }else{ return $str; } }
也就是说在要递归的函数内部的函数前面要加return spa