I'm trying to produce 25 variables from $day1Txt through to $day2Txt.
How do I turn the '1' in the variable $day1Txt
into the variable $i
?
for ($i = 1; $i < 25; $i++) {
$day1Txt = echo call_user_func('Day_'.$i.'_Offer', 'EMAIL_OFFER');
}
I've made an attempt myself but it white screens...
${'day'.$i.'Txt'} = echo call_user_func('Day_'.$i.'_Offer', 'EMAIL_OFFER');
This should help you(remove echo
).
for ($i = 1; $i < 25; $i++) {
${"day".$i."Txt"} = call_user_func('Day_' . $i . '_Offer', 'EMAIL_OFFER');
}
If you want to see what all variables are there in your function use get_defined_vars()
.
See deme here
Try this
for ($i = 1; $i < 25; $i++) {
${"day".$i."Txt"} = call_user_func('Day_'.$i.'_Offer', 'EMAIL_OFFER');
}
It's called Variable variables ie a variable name which can be set and used dynamically