0

I'm calling a function that prints an output using "echo". for example:

function a(){
   echo 'example output';
}

problem is I don't have any control over this function and can't edit it. but I need to store the function's output to a variable like so:

$myVar = a();
// $myVar should now be 'example output'

I need to prevent the function from printing anything to the screen but I need it's output in $myVar.

is there anyway to achieve this?

rami300
  • 69
  • 9
  • 1
    change `echo example output` to `return example output` – B001ᛦ Jan 23 '20 at 11:41
  • I specifically mentioned I can't edit the function. that's the whole issue about it. – rami300 Jan 23 '20 at 11:58
  • Can you speak to the person who _does_ control it and ask them to improve it? (Or if it's just some code you downloaded and included in your script, there's actually nothing to stop you changing it really). – ADyson Jan 23 '20 at 12:23

0 Answers0