JJohnsenDK Posted September 8, 2008 Share Posted September 8, 2008 Hey Why doesnt this function return the result in $returnstr? I can echo the result inside the if statement, as you can see in the code. So where is the error? <?php function f($str){ $returnstr = "Resultat: "; if(findLastCharInString($str) == "("){ $returnstr .= substr($str, 0, -1); echo $returnstr."<br>"; }else{ echo $str."<br>"; f(substr($str, 0, -1)); } return $returnstr."222"; } $test = f("Mohair sokker sort (Large)"); echo "test: ".$test; ?> Link to comment https://forums.phpfreaks.com/topic/123326-solved-why-doesnt-this-function-return-the-result/ Share on other sites More sharing options...
genericnumber1 Posted September 8, 2008 Share Posted September 8, 2008 it calls f() on the inside, and returns it to the else{} statement... but you don't do anything with it so it's lost. Try changing f(substr($str, 0, -1)); to $returnstr = f(substr($str, 0, -1)); that MIGHT return what you expect, it might return something else (I don't know what you want).... at least it will give you some idea of how to refine your function (which, frankly, could probably be done more efficiently and safer); Link to comment https://forums.phpfreaks.com/topic/123326-solved-why-doesnt-this-function-return-the-result/#findComment-636952 Share on other sites More sharing options...
JJohnsenDK Posted September 8, 2008 Author Share Posted September 8, 2008 Works! thanks genericnumber1! Link to comment https://forums.phpfreaks.com/topic/123326-solved-why-doesnt-this-function-return-the-result/#findComment-636956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.