选择时获取值

I'm on the learning mode.

<?php
if (!empty($_POST['fifty']) || !empty($_POST['sixty'])) {
    $fifty = (isset($_POST['fifty'])) ? (int)$_POST['fifty'] : 0;
    $sixty = (isset($_POST['sixty'])) ? (int)$_POST['sixty'] : 0;
    echo $fifty + $sixty;
} else {
    echo "No selection selected";
}
?>
<form method="post">
    <input type="radio" name="fifty" value="50"/>
    <input type="radio" name="sixty" value="60"/>
    <input type="submit" name="submit" value="Submit"/>
</form>

This only works when I select both radio buttons. How do I make this work when I just select 1 radio button instead of 2?

And is the way I coded the PHP the good way to write it? I get an idea that I do double work with checking :P

And how do I do it with three radio options? Can you give me a example with a third radio option called seventy with value 70?

My idea is to make it + count the values if 1 and 3 are slected it must to 50+70 if 2 and 3 are selected it must do 60 + 70, etc, etc.

Use ||for OR, && for AND

if(!empty($_POST['fifty']) || !empty($_POST['sixty'])){
   $fifty = (isset($_POST['fifty']))? (int)$_POST['fifty'] : 0;
   $sixty = (isset($_POST['sixty']))? (int)$_POST['sixty'] : 0;
   echo $fifty + $sixty;
} else {
  echo "No selection selected"; 
}

A few things to change.

  1. The <input /> tags.

    <input type="radio" name="fifty" value="50" />
    <input type="radio" name="sixty" value="60" />
    
  2. The logic you used (which you have corrected).

    if (!empty($_POST['fifty']) || !empty($_POST['sixty']))
    
  3. Remove unnecessary code:

    $submit = $_POST['submit'];