Forum Moderators: coopster
// this is the original; it's shortened for this post, so please ignore any typos or logic flaws
if (is_numeric($g)) $this_g = $g;
else {
// default if nothing in the loop matches
$this_g = 1;
for ($g = 0; $g < 10; $g++)
if ($foo === $bar[$g])
$this_g = $g;
}
// ternary version that I thought would work, but doesn't
$this_g = is_numeric($g) ? $g : function() {
for ($g = 0; $g < 10; $g++)
if ($foo === $bar[$g])
return $g;
// default if return hasn't been sent
return 1;
}; // in a weak attempt to limit confusion, I changed the name here from $this_g to $func
$func = is_numeric($g) ? function() use ($g) { return $g; } : function() use ($foo, $bar) {
for ($g = 0; $g < 10; $g++)
if ($foo === $bar[$g])
return $g;
// default if return hasn't been sent
return 1;
};
$this_g = $func();