Forum Moderators: coopster
for example:
$lines = "$condition1==apples ¦¦ $condition2==pears ¦¦ $condition3==plums"
I know that the conditional statement is getting built properly because I was able to echo it to make sure. The problem is that I can't get the string in $lines to be evaluated inside the if() condition. I have a feeling that I may need to use the eval() function, but am not sure how to do this. Help please :)
The code in question looks like this
if($lines) {
Do something....
}else{
Do something else
}
Thanks
Yes, I've been trying to find a way to use eval().
The snippet of code I posted earlier is in a loop, this is a more accurate representation of what I am trying to do.
$lines = "$condition==2 ¦¦ $condition==6 ¦¦ $condition==15";
$list=40;
for ($condition=1; $condition<=$list; $condition++) {
if (eval("\$lines=\"$lines\";")) {
Do something....
}else{
Do something else...
}
}
the problem I have is that the value of $condition doesn't increase in the eval'd statement, it stays at "1" for each occurrence of $condition in $lines, which kinda makes sense...
the more I play with this I am thinking maybe I am approaching it from the wrong angle?
[php.net ]
<?php
$lines = '$condition==2 ¦¦ $condition==6 ¦¦ $condition==15';
$list=40;
for ($condition=1; $condition<=$list; $condition++) {
if (eval("return $lines;")) {
// Do something
} else {
// Do something else
}
}
?>