Page 1 of 1
Better way to write this????
Posted: Tue Dec 07, 2004 10:45 pm
by neophyte
Code: Select all
<?php
if ( $temp['type'] == "input")
{
$label = "";
}
elseif ( $temp['type'] == "submit" )
{
$label ="";
}
elseif ( $temp['type'] == "reset" )
{
$label="";
}
else
{
$label = $prepkey;
}
?>
Isn't there a better way to do this?
You know like maybe:
Code: Select all
<?php
if ( $temp['type'] == ("input" || "submit" || "reset"))
{
$lablel="";
}
else
{
$label = $prepkey;
}
?>
is that a correct way of re-writing it? If not can some one suggest a tighter more compact or simpler way of coding that? Thanks
Posted: Tue Dec 07, 2004 10:52 pm
by kettle_drum
Maybe:
Code: Select all
switch($temp['type']){
case 'input':
case 'submit':
case 'reset':
$label = "";
break;
case default:
$label = $prepkey;
}
You would have to test to see what was fastest.
Posted: Tue Dec 07, 2004 10:53 pm
by timvw
i probably would do it with a switch
Code: Select all
switch ($tempї'type']) {
case "input":
case "submit":
case "reset":
$result = "";
break;
default:
$result = $prepkey;
}
or with in_array
Code: Select all
$values = array('submit', 'input', 'reset');
if (in_array($temp['type'], $values)
{
$result = "";
}
else
{
$result = $prepkey;
}
Posted: Tue Dec 07, 2004 11:04 pm
by neophyte
Great guys thanks for the suggestions! That oughta do it.