Originally posted by tomwerner
The thing is that the eval() call spits out an error. Any ideas?
What is the error that is spat out?
Looking at the generated source:
$event[\"{$x}\"]
looks dodgy: surely $event[$x] would be sufficient there as for everywhere else.
Here's another suggestion: use a for loop, then the code is likely to be a lot cleaner. This is equivalent:
$count = count($event);
for($x=0; $x<=$count; $x++)
{
$dateinfo .= 'if($x == $event[$x]["day"] & $month == $event[$x]["month"] & $year == $event[$x]["year"]){
$link="Popup('cal_dwnld_popup.php?month=$event[$x][\"month\"]&year=$event[$x][\"year\"]&title=$event[$x][\"title\"]');";
} else {';
}
for($x=0; $x<=$count+1; $x++)
{
$dateinfo .= '}';
}
// The eval call
eval($dateinfo);
The first loop runs off the end of the $event[] array and the second runs even further.
Also note that because you're using singule-quoted strings, $x won't actually be evaluated: notice in the generated code that all of the tests and resulting code branches are exactly the same.
I'm not even sure that eval() is even needed. What is the actual output you're trying to achieve from all this? Can the same result not be achieved by just running the code rather than building it up in a string and then running it?