lundi 10 octobre 2016

In PHP how do you do an if statement within the if of an if statement?

So the question is confusing I know. This is what I am wondering how to do.

I have the following if statement:

if(
    (isset($_POST['billing_company']) && $_POST['billing_company'] != "") && 
    (isset($_POST['billing_address']) && $_POST['billing_address'] != "") && 
    (isset($_POST['billing_city']) && $_POST['billing_city'] != "") && 
    (isset($_POST['billing_state']) && $_POST['billing_state'] != "") && 
    (isset($_POST['billing_zip']) && $_POST['billing_zip'] != "") && 
    (isset($_POST['billing_phone']) && $_POST['billing_phone'] != "") && 
    (isset($_POST['location_name']) && $_POST['location_name'] != "") && 
    (isset($_POST['location_address']) && $_POST['location_address'] != "") && 
    (isset($_POST['location_city']) && $_POST['location_city'] != "") && 
    (isset($_POST['location_state']) && $_POST['location_state'] != "") && 
    (isset($_POST['location_zip']) && $_POST['location_zip'] != "") && 
    (isset($_POST['location_phone']) && $_POST['location_phone'] != "") && 
    (isset($_POST['user_firstname']) && $_POST['user_firstname'] != "") && 
    (isset($_POST['user_lastname']) && $_POST['user_lastname'] != "") && 
    (isset($_POST['user_username']) && $_POST['user_username'] != "") && 
    (isset($_POST['user_email']) && $_POST['user_email'] != "") && 
    (isset($_POST['user_password']) && $_POST['user_password'] != "") && 
    (isset($_POST['user_mobile']) && $_POST['user_mobile'] != "") && 
    (isset($_POST['payment_cc_name']) && $_POST['payment_cc_name'] != "") && 
    (isset($_POST['payment_cc_number']) && $_POST['payment_cc_number'] != "") && 
    (isset($_POST['payment_cc_expo_month']) && $_POST['payment_cc_expo_month'] != "") && 
    (isset($_POST['payment_cc_expo_year']) && $_POST['payment_cc_expo_year'] != "") && 
    (isset($_POST['payment_cc_code']) && $_POST['payment_cc_code'] != "") && 
    (isset($_POST['terms']) && $_POST['terms'] != "")
){

However, based on some variables, I may no longer need any of the billing information. So I am wondering if I can do an IF inside the IF, so something like this:

if(
    ($billingRequired == 1){
        (isset($_POST['billing_company']) && $_POST['billing_company'] != "") && 
        (isset($_POST['billing_address']) && $_POST['billing_address'] != "") && 
        (isset($_POST['billing_city']) && $_POST['billing_city'] != "") && 
        (isset($_POST['billing_state']) && $_POST['billing_state'] != "") && 
        (isset($_POST['billing_zip']) && $_POST['billing_zip'] != "") && 
        (isset($_POST['billing_phone']) && $_POST['billing_phone'] != "") && 
    }
    (isset($_POST['location_name']) && $_POST['location_name'] != "") && 
    (isset($_POST['location_address']) && $_POST['location_address'] != "") && 
    (isset($_POST['location_city']) && $_POST['location_city'] != "") && 
    (isset($_POST['location_state']) && $_POST['location_state'] != "") && 
    (isset($_POST['location_zip']) && $_POST['location_zip'] != "") && 
    (isset($_POST['location_phone']) && $_POST['location_phone'] != "") && 
    (isset($_POST['user_firstname']) && $_POST['user_firstname'] != "") && 
    (isset($_POST['user_lastname']) && $_POST['user_lastname'] != "") && 
    (isset($_POST['user_username']) && $_POST['user_username'] != "") && 
    (isset($_POST['user_email']) && $_POST['user_email'] != "") && 
    (isset($_POST['user_password']) && $_POST['user_password'] != "") && 
    (isset($_POST['user_mobile']) && $_POST['user_mobile'] != "") && 
    (isset($_POST['payment_cc_name']) && $_POST['payment_cc_name'] != "") && 
    (isset($_POST['payment_cc_number']) && $_POST['payment_cc_number'] != "") && 
    (isset($_POST['payment_cc_expo_month']) && $_POST['payment_cc_expo_month'] != "") && 
    (isset($_POST['payment_cc_expo_year']) && $_POST['payment_cc_expo_year'] != "") && 
    (isset($_POST['payment_cc_code']) && $_POST['payment_cc_code'] != "") && 
    (isset($_POST['terms']) && $_POST['terms'] != "")
){

I'm pretty sure there isn't but wanted to check with people smarter than me. I know I can do some nesting in side the {} but wanted to not have to check each variable inside a very deep nest.

Thanks,

Aucun commentaire:

Enregistrer un commentaire