Antivirus
06-02-2008, 04:53 PM
I have the following 3 different eval statements based upon a conditional...
foreach ($sc_gblockinfo AS $sc_gblock)
{
if ($sc_gblock['pos'] == 'top')
{
eval('$sc_gblockbits_top .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
else if ($sc_gblock['pos'] == 'left')
{
eval('$sc_gblockbits_left .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
else if ($sc_gblock['pos'] == 'right')
{
eval('$sc_gblockbits_right .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
}
however i know it could be written more efficiently, and I have tried the following, along with different variations, however I just can't seem to figure it out...
foreach ($sc_gblockinfo AS $sc_gblock)
{
eval('$sc_gblockbits_' . $sc_gblock['pos'] . ' .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
Within the loop, $sc_gblock['pos'] can be one of three possibilities, 'top', 'left', or 'right'... I'm basically just looking for a more compact way of writing the first example above.
Anyone got an idea of how to do this correctly?
foreach ($sc_gblockinfo AS $sc_gblock)
{
if ($sc_gblock['pos'] == 'top')
{
eval('$sc_gblockbits_top .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
else if ($sc_gblock['pos'] == 'left')
{
eval('$sc_gblockbits_left .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
else if ($sc_gblock['pos'] == 'right')
{
eval('$sc_gblockbits_right .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
}
however i know it could be written more efficiently, and I have tried the following, along with different variations, however I just can't seem to figure it out...
foreach ($sc_gblockinfo AS $sc_gblock)
{
eval('$sc_gblockbits_' . $sc_gblock['pos'] . ' .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
Within the loop, $sc_gblock['pos'] can be one of three possibilities, 'top', 'left', or 'right'... I'm basically just looking for a more compact way of writing the first example above.
Anyone got an idea of how to do this correctly?