3
\$\begingroup\$

I'm evaluating a meeting_type value that determines what kind of pricing structure I should be using. Currently, if my meeting_type value is a w, we charge one price for every 10 registrants. If the meeting_type is anything else, it's a price per registrant model.

I'm using this logic:

if($_POST['meeting_type'] != 'w'){          
    $total_price = $guests * $price;
}
else{
    $webinar_count = ceil($guests / 10);
    $total_price = $webinar_count * $price;
}

Is this logic flawed? Can it be improved upon?

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Removing intermediate variable $webinar_count

$total_price = ($_POST['meeting_type'] == 'w')
             ? (ceil($guests / 10) * $price)
             : ($guests * $price);

OR

if ($_POST['meeting_type'] != 'w') {
    $total_price = $guests * $price;
} else {
    $total_price = ceil($guests / 10) * $price;
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.