PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
neophyte
DevNet Resident
Posts: 1537 Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota
Post
by neophyte » Tue Dec 07, 2004 10:45 pm
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
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Tue Dec 07, 2004 10:52 pm
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.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Tue Dec 07, 2004 10:53 pm
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;
}
neophyte
DevNet Resident
Posts: 1537 Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota
Post
by neophyte » Tue Dec 07, 2004 11:04 pm
Great guys thanks for the suggestions! That oughta do it.