output buffering a function parameter

I have two simple PHP functions:

<? 
  function print_txt($text) {
    echo $text;
  }

  function store_data($name,$data){
    define($name,$data);
  }
?>

I want the second function to store data and use it later whenever I want but when I try to put the first function as a parameter it prints it directly.

E.g : store_data('my_data',print_text('hello world')); when I reload the page the 'hello world' string appears

Is there any way to keep the data and control it ? Something like output buffering maybe ?

Answers


The method echo do not have any return value. Return the value in print_txt after you have print it:

return $text;

Or did not I get your question?


Need Your Help

How to sum up datagridview columns by unique id's?

c# csv datagridview

I have a datagridview which is populated with records from .csv file (around 30k records with 30-40 unique id's - depends on file). It looks like this:

How to check if a file exists when it was no file extension? C#

c# file io exists

The file test has no extension and I need help to either move or rename this file to something with a extension