|
Posted by jerrygarciuh on 06/08/07 17:33
Hello,
I am converting a large scale app from Perl TemplateToolkit and
Class::DBI to PHP.
TemplateToolkit has elegant ways of coping with variables that may be
a scalar or may be an array. So my predecessor has a number of vars
that are ambiguous in this way.
My question to you is whether, given this ambiguity, there is a better
way to do this in PHP than my current solution?
// $a is sometimes an array
$a = array('foo', 'bar', 'kermit ruffins');
if (is_array($a)) {
foreach($a as $b) {
if (preg_match('/ruffin/', $b)) {
echo 'ruffin found';
}
}
} else {
if (preg_match('/ruffin/', $a)) {
echo 'ruffin found';
}
}
Much obliged for any help!
Peace,
JG
Navigation:
[Reply to this message]
|