function createUniqueName($name, $i = 0)
{
$names = array('backup');
if($i != 0) {
$newname = $name.'-'.$i;
} else {
$newname = $name;
}
if(in_array($newname, $names)) {
$newname = createUniqueName($name, $i++);
}
return $newname;
}
echo createUniqueName('backup', 0);
不幸的是,这会导致内存泄漏,我不知道为什么。它是一个正常的递归。有任何想法吗?
收到的错误是:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 130968 bytes) in /Users/Tim/Sites/tests/uniquename.php on line 16