[英]PHP function returns NULL
I have the following function: 我有以下功能:
function MyReplaceListTag($myText,$number){
if (strpos($myText,'<li>')===FALSE){
$myResult= strip_tags($myText);
return $myResult;
}else{
$number++;
$pattern= '/<li>/';
$replacement = "\n".$number."- ";
$myText=preg_replace ( $pattern , $replacement , $myText , 1 );
MyReplaceListTag($myText,$number);
}
}
I call it with: 我称它为:
$result = MyReplaceListTag( $testTEXT,0);
Nothing is returned, var_dump($result) gives NULL. 什么也没有返回,var_dump($ result)给出NULL。
I must be doing something incredibly stupid, but what? 我一定在做一件令人难以置信的愚蠢的事情,但是呢?
Your function is returning NULL
on the else
block because it's lacking a return statement. 您的函数在
else
块上返回NULL
,因为它缺少return语句。
Change the else
block from: 从以下位置更改
else
块:
MyReplaceListTag($myText,$number);
to 至
return MyReplaceListTag($myText,$number);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.