I recently started working with PHP and I am trying to create a function that will return the content what I want to show. So that means I need to store the value of these contents in a variable in each case block and then return that variable value at the end.
<?php
function sidebarContent($id) {
switch ($id) {
case "21":
// how to store these values in a variable
<p>Hello ABC.</p>
<p class="content-register"><a href="/abc">Abc</a></p>
break;
case "31":
// how to store these values in a variable
<p>Hello DEF.</p>
<p class="content-register"><a href="/Def">Def</a></p>
break;
case "41":
// how to store these values in a variable
echo "Your favorite color is green!";
<p>Hello GHI.</p>
<p class="content-register"><a href="/Ghi">Ghi</a></p>
break;
default:
// how to store these values in a variable
<p>Hello World.</p>
}
// how do I return content here?
}
// call above function to test out
?>
I am not able to understand how to store content values in a variable and then return at the end?
=operator, or you can use "output buffering".