PHP如果在表单输入中

I want the $delivery in the top input to change value depending on the value on another variable I'm using.

I'm just not sure how to place another if inside the current if and how to match up the value="0.00" so it all works together

<form action="" method="post" onclick="this.submit()">
    <input <?php if ($delivery=='0.00'){ echo 'checked="checked"';} ?> type="radio" value="0.00" name="delivery">&nbsp; Economy - up to 4 working days<br>
    <input <?php if ($delivery=='4.99'){ echo 'checked="checked"';} ?> type="radio" value="4.99" name="delivery">&nbsp; Express - next day <br>
    <input <?php if ($delivery=='9.99'){ echo 'checked="checked"';} ?> type="radio" value="9.99" name="delivery">&nbsp; Saturday<br>
</form>

Thanks.

What i ended up doing was this:

if ($pricetotal <= 50.00) {
$amount1 = 3.99;
}
elseif ($pricetotal >= 50.01) {
$amount1 = 0.00;
}

Then in my form changing it to this:

<form action="" method="post" onclick="this.submit()">
<input <?php if ($delivery<='3.99'){ echo 'checked="checked"';} ?> type="radio" value="       <?php echo htmlspecialchars($amount1); ?>" name="delivery">&nbsp; Economy - up to 4 working days<br>
<input <?php if ($delivery=='4.99'){ echo 'checked="checked"';} ?> type="radio" value="4.99" name="delivery">&nbsp; Express - next day <br>
<input <?php if ($delivery=='9.99'){ echo 'checked="checked"';} ?> type="radio" value="9.99" name="delivery">&nbsp; Saturday<br>

I might not have explained exactly what i needed as i thought there would be a simple fix, but i wanted the top inputs value do change depending on $pricetotal and i managed to get it working.

Thanks for the help.

I would do something like this:

$deliveryEconomy = '';
$deliveryExpress = '';
$deliverySaturday = '';

switch($delivery)
{
   case 0.00:
   $deliveryEconomy = 'checked="checked"';
   break;

   case 4.99:
   $deliveryExpress = 'checked="checked"';
   break;

   case 9.99:
   $deliverySaturday = 'checked="checked"';
   break;
}

<form action="" method="post" onclick="this.submit()">
<?php 
echo "<input $deliveryEcononomy type='radio' value='0.00' name='delivery'>&nbsp; Economy - up to 4 working days<br>";
echo "<input $deliveryExpress type='radio' value='4.99' name='delivery'>&nbsp; Express - next day <br>";
echo "<input $deliverySaturday type='radio' value='9.99' name='delivery'>&nbsp; Saturday<br>";
?>
</form>

Normally you would run logic before this, but if you are looking for a quick and dirty mini-if statement, something like this might work for you:

if ($delivery==($boolVar ? '0.00' : 'something else')){ echo 'checked="checked"';}

These statements have the same result:

if($condition) {
    $var = $statement_1;
} else {
    $var = $statement_2;
}

$var = $condition ? $statement_1 : $statement_2;

Don't overuse it however, otherwise you may be tempted to try:

$var = $condition_1 ? $statement_1 : ($condition_2 ? $statement_2 : $statement_3);

Messy.