输入if / else语句时数组或变量丢失值

时间:2018-07-18 11:09:23

标签: php laravel

这是我声明$ list值的一些代码。

$list['first_name']            = Request::input("first_name");
$list['last_name']             = Request::input("last_name");

当我使用dd($ list)时,它显示的值类似于我的snipped image

但是当它输入此if else语句时,

if($existing_customer)
{
     $customer_id            = $existing_customer->customer_id;
}
else
{
    dd($list);
    $insert_customer["first_name"]     = ($list['first_name'] == "undefined" ? "John" : ucfirst($list['first_name']));
    $insert_customer["last_name"]      = ($list['last_name'] == "undefined" ? "Doe" : ucfirst($list['last_name']));
}

这是result

这是我的照片,如果有帮助的话。 first second

public function import_submit()
{
    $data                       = Self::get_initial_settings();
    /* INITIALIZE AND CAPTURE DATA */
    $shop_id                    = $this->user_info->shop_id;
    $sponsor                    = Tbl_mlm_slot::where("slot_no", Request::input("sponsor"))->where("shop_id", $shop_id)->value("slot_id");
    $placement                  = Tbl_mlm_slot::where("slot_no", Request::input("placement"))->where("shop_id", $shop_id)->value("slot_id");

    /* POSITIONING DATA */
    $slot_sponsor               = $sponsor;
    $slot_placement             = $placement;
    $slot_position              = strtolower(Request::input("position"));


    /* SLOT GENERATION */
    $membership_package_id      = Request::input("package_number");


    /* JUST ADD TO SLOT IF EXISTING CUSTOMER */


    if(Request::input("date_created") == "undefined")
    {
        $slot_date_created      = date("Y-m-d h:i");
    }
    else
    {
        $slot_date_created      = date("Y-m-d", strtotime(Request::input("date_created")));
    }

    $existing_customer          = Tbl_customer::where("shop_id", $shop_id)->where("email", Request::input("email"))->first();

    $list['first_name']            = Request::input("first_name");
    $list['last_name']             = Request::input("last_name");
    $list['email']                 = Request::input("email");
    $list['slot_no']               = Request::input("slot_no");
    $list['password']              = Request::input("password");
    $list['birthday']              = Request::input("birthday");
    $list['contact']               = Request::input("contact_number");
    $list['gender']                = Request::input("gender");

    dd($list); <---- first run of the function, I put one here


    if($existing_customer)
    {
        $customer_id            = $existing_customer->customer_id;
    }
    else
    {
        dd($list); <--- for the second run of the function, to check what happens to my $list
        $insert_customer["shop_id"]        = $shop_id;
        $insert_customer["first_name"]     = ($list['first_name'] == "undefined" ? "John" : ucfirst($list['first_name']));
        $insert_customer["last_name"]      = ($list['last_name'] == "undefined" ? "Doe" : ucfirst($list['last_name']));

        $insert_customer["email"]          = ($list['email'] == "undefined" ? "dummy@gmail.com" : $list['email']);
        $insert_customer["ismlm"]          = 1;
        $insert_customer["mlm_username"]   = $list['slot_no'];
        $insert_customer["password"]       = ($list['password'] == "undefined" ? Crypt::encrypt(randomPassword()) : Crypt::encrypt($list['password']));
        $insert_customer["created_date"]   = $slot_date_created;
        $insert_customer["b_day"]          = date("Y-m-d", strtotime($list['birthday']));
        $insert_customer["birthday"]       = date("Y-m-d", strtotime($list['birthday']));
        $insert_customer["contact"]        = $list['contact'];
        $insert_customer["gender"]         = strtolower($list['gender']);

        $customer_id = Tbl_customer::insertGetId($insert_customer);

        /* Insert Customer Address */
        $address_purpose[0] = "permanent";
        $address_purpose[1] = "billing";
        $address_purpose[2] = "shipping";

        foreach ($address_purpose as $key => $value) 
        {
            $insert_customer_address["customer_id"] = $customer_id;
            $insert_customer_address["country_id"] = 420;
            $insert_customer_address["customer_state"] = "";
            $insert_customer_address["customer_city"] = "";
            $insert_customer_address["customer_zipcode"] = "";
            $insert_customer_address["customer_street"] = Request::input("address");
            $insert_customer_address["purpose"] = $value;
            $insert_customer_address["archived"] = 0;
            $insert_customer_address["created_at"] = Carbon::now();
            $insert_customer_address["updated_at"] = Carbon::now();

            Tbl_customer_address::insert($insert_customer_address);
        }
    }
}

我真的看不到哪里出错了,因为这些值变为null仅仅是因为它们输入了if / else语句。

0 个答案:

没有答案