1

I have a question about my functions. Let me explain, I have two functions:

/* This function works properly
; example : echo first('Hello world', 'return');
*/
function first($string, $return = 'echo')
{
 if($return == 'echo')
 {
  echo $string;
 }
 else
 {
  return $string;
 }
}

And this is second, function, is calling first function.

/* This function doesn't works
; example : echo second('my string', 'return');
*/
function second($string, $return = 'echo')
{
 first($string, $return);
}

The problem is I want the second function like that, as simple as above.

0

1 Answer 1

4

You need to return from second(). Otherwise, first(), called inside it, will echo output, but the value it returns to its caller (second()) goes nowhere and is lost. Return the value of the call to first() from second().

function second($string, $return = 'echo')
{
  return  first($string, $return);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Wow, looks legit :) thanks... That worksssss, sorry You can accept an answer in 8 minutes.
Exactly, you get the value from first() but second() didn't know what to do with it. So, it just stopped doing anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.