So maybe I'm just having a brain hiccup, idk. But it seems like this should work but it doesn't.
The Intent
Build a string throughout a page for use later on in the app page.
The Question
How do we store a string in a way that we can add to it with a function several times before using the resulting value of the string? Is there a better way to do this with a function than to use a variable?
A Non-Working Example
<?php
$testNG = "";
function testNG($tng){
$testNG .= $tng;
return $testNG;
}
testNG("hello!!");
?>
<h2><?= $testNG; ?></h2>
As always, thank you all for contributing to making the online world a much more efficient place!
Edit
An example purpose for this would be to allow Javascript to be aggregated into a variable so that it can be created near the elements it effects, then placed in a section before the </body>
<div id="rating"></div>
<?php testNG("$('#rating').rating();"); ?>
<p>blah blah</p>
...
...
</footer>
<?php
if($testNG != ""): ?>
<script>
<?= $testNG; ?>
</script>
<?php endif; ?>