milesdriven
07-21-2012, 04:44 PM
To pose my question in a way that makes it clear what I'm asking, I'll start with a simple example. Here is a heredoc:
$tree = <<<DEMO
This is day 1
DEMO;
print $tree;
I want to place this heredoc in a for loop, so it is repeated once for each day of the month. I'll use January as an example. I want to place variables in the heredoc shown above, so the iteration for each day of the month is unique so php will create 31 of them.
My thought is the $tree variable and the DEMO delimiter both need information about the days in January incorporated into them to make each iteration truly unique.
The example below is what I think I need to do. I put the raw data in instead of the variables to try to make the question I'm asking clear. The example below would work to make one iteration that is Jan 1 2012:
$treeJan12012 = <<<DEMO1
DEMO1;
print $treeJan12012;
This example would be Jan 2 2012:
$treeJan22012 = <<<DEMO2
DEMO2;
print $treeJan22012;
What I'm trying to do is something like this:
$month = date('M');
$days = date('t');
$year =('Y')
for($k = 1, $k <= $days, $k++)
{
$tree.$month.$days.$year = <<<DEMO$days
DEMO$days;
print $tree.$month.$days.$year;
}
What I just did in the example above doesn't look right, but it shows you what I'm trying to do. How do I put these variables in there so php will use them to make 31 unique heredocs?
Thank you
$tree = <<<DEMO
This is day 1
DEMO;
print $tree;
I want to place this heredoc in a for loop, so it is repeated once for each day of the month. I'll use January as an example. I want to place variables in the heredoc shown above, so the iteration for each day of the month is unique so php will create 31 of them.
My thought is the $tree variable and the DEMO delimiter both need information about the days in January incorporated into them to make each iteration truly unique.
The example below is what I think I need to do. I put the raw data in instead of the variables to try to make the question I'm asking clear. The example below would work to make one iteration that is Jan 1 2012:
$treeJan12012 = <<<DEMO1
DEMO1;
print $treeJan12012;
This example would be Jan 2 2012:
$treeJan22012 = <<<DEMO2
DEMO2;
print $treeJan22012;
What I'm trying to do is something like this:
$month = date('M');
$days = date('t');
$year =('Y')
for($k = 1, $k <= $days, $k++)
{
$tree.$month.$days.$year = <<<DEMO$days
DEMO$days;
print $tree.$month.$days.$year;
}
What I just did in the example above doesn't look right, but it shows you what I'm trying to do. How do I put these variables in there so php will use them to make 31 unique heredocs?
Thank you