I made a simple framework to deepen my understanding regarding php. In my controller, I write the below code to show view:
$varString = "test";
$varArray = array("a", "b", "c");
include __DIR__ . './homepage.php';
The real weird thing is, both the variable is available inside the homepage.php file as I can get its value via var_dump. But as I try to loop the $varArray using foreach as below:
<? foreach($varArray as $value): ?>
<?= $value; ?>
<? endforeach; ?>
I get the following error,
Notice: Undefined variable: value
Also, adding to this confusion, there is no problem echoing $varString using echo like this:
<?= $varString; ?>
Anyone had the same issue as this before? Note that I am doing all this inside the homepage.php file.