I have a class Constant in App\Utilities See Below:
<?php
class Constant {
const
WEEK_1 = 'Week 1',
WEEK_2 = 'Week 2';
}
?>
And I can echo Constant::WEEK_1 it gives me 'Week 1',
But what I want is to dynamically call constant week say
foreach([1,2] as $key => $num) {
echo Constant::'WEEK_'.$num
}
And Im getting a parse error.
How to do this? Anyone? Thanks
I found the answer my self by doing:
echo constant('App\Utilities\Constant::WEEK_'.$num);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With