note 109017 deleted from language.types.string by danbrown

From: Date: Wed, 13 Jun 2012 14:52:05 +0000
Subject: note 109017 deleted from language.types.string by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188560@lists.php.net to get a copy of this message
Note Submitter: kgeiger at computer dot org ---- Like "headden at karelia dot ru" (20-Jun-2009 12:43) and others, it would be great to print the return value of a function in a string, heredoc, etc. This workaround stores the function's computed result in a uniquely-named global, then returns the global's name for interpretation as part of the string. The function call embedded in the string simply displays the resulting value. <?php function someFunction ($t) { global $someFunction_return_value; $someFunction_return_value = $t*$t + $t; return 'someFunction_return_value'; } $x = 23; $y = 7; header("Content-type: text/plain"); print <<<__TXT__ Value of $x^2 + $x is {${someFunction($x)}} Value of $y^2 + $y is {${someFunction($y)}} __TXT__; ?>

« previous php.notes (#188560) next »