Dear friends, I have this question about 'in_array()' returning "TRUE":
Suppose I have this piece of code:
<?php
$suspects = Array(Alfred, Bob, Charles, Davis, Edward, Frank);
function Bolo () {
global $suspect;
global $cond1, $cond2, $cond3, $val1, $val2, $val3, $output1, $output2, $output3, $output4;
if ($cond1 == $val1) {$output1;}
elseif ($cond2 == $val2) {$output2;}
elseif ($cond3 == $val3) {$output3;}
else $output4;
} // end function Bolo;
==== LETS GO ! ====
$cond1=$suspect;
$val1='Alfred';
$output1='print "Suspect Alfred spotted";';
$cond2=$suspect;
$val2='Bob';
$output2='print "Suspect Bob spotted";';
$output4='print "That is not a suspect";';
eval("print Bolo();");
?>
So far, so good. Now suppose I want to this instead of the above:
<?php
$suspects = Array(Alfred, Bob, Charles, Davis, Edward, Frank);
function Bolo () {<the same function as above>}
==== LETS GO ! ====
$cond1='in_array ($suspect, $suspects)';
$val1='TRUE';
$output1='"Suspect $suspect spotted";';
$output4='print "That is not a suspect";';
eval("print Bolo();");
?>
My problem is: if I say
if (in_array ($suspect, $suspects)) {$output1;}
it works fine. But I really need to be able to say
if ($cond1 == $val1) {$output1;}
It is some kind of template that I need to repeat many times in a page, and I really wish I could make 'in_array' fit in that ($cond1 == $val1) formula, so that it would fit in the same function that ALL other conditions in the page will use instead of cutting the flow and introducing another function for that condition only. I thought I could check 'in_array()' against "TRUE", but it is not working. Anybody got any ideas?
Thank yous,
Luciano ES
Santos - SP - Brasil