0
function saveWeixinFile($filename, $filecontent)
{
    if(!file_exists($filename))
    {
        $local_file = fopen($filename, 'w');
        if(false !== $local_file)
        {
            if(false !== fwrite($local_file, $filecontent))
            {
                
                fclose($local_file);
                var_dump($filename);
                return $filename;
            }
        }
    }else{
        $filenameex = explode('.',$filename);
        $bracketsleft = strrpos($filenameex[0],'(');
        if($bracketsleft)
        {
            $countleng = strlen($filenameex[0]);
            $num = substr($filenameex[0],$bracketsleft+1,$countleng-$bracketsleft-2);
            $numadd = $num+1;
            $filename = str_replace('('.$num.')','('.$numadd.')',$filename);
        }else{
            $num = 1;
            $filename = $filenameex[0].'('.$num.').'.$filenameex[1];
        }
        saveWeixinFile($filename, $filecontent);
    }
}
var_dump(saveWeixinFile('text.txt','aa'));

这段代码,第一次运行是有返回值的,但是从第二次运行开始就没有返回值了,每次在return前面var_dump($filename);都是有打印的,请问是什么原因导致返回为null呢。是运行次数,不是代码递归的次数

2019-01-15 提问
1 个回答

撰写答案

推广链接