解析错误:语法错误,意外T_IF,期待')'我该怎么办?

时间:2016-09-21 10:00:06

标签: php

  

解析错误:语法错误,意外T_IF,期待')'

我该怎么办?请任何人帮助我

         $option = $_GET['I-would-like'];
         $userdata = array(
            'user_login' => $username,
            'user_pass' => $password,
            'user_email' => $email,
            'nickname' => reset($name_parts),
            'display_name' => $name,
            'first_name' => reset($name_parts),
            'last_name' => end($name_parts),    
            if ($option == 'A quotation' OR  $option == 'Information')// Error occurs here
        {
            'role' => 'customer'
            } else if($option == 'To become a Partner') 
            {
            'role' => 'partners'
            } else if ($option == 'Training / Coaching')
                {
            'role' => 'students'
            }
        );

2 个答案:

答案 0 :(得分:1)

Update with below code,

 $option = $_GET['I-would-like'];

    if ($option == 'A quotation' OR  $option == 'Information')
    {
        $role='customer';
    } else if($option == 'To become a Partner') 
    {
        $role='partners';
    } else if ($option == 'Training / Coaching')
    {
        $role='students';
    }


    $userdata = array(
        'user_login' => $username,
        'user_pass' => $password,
        'user_email' => $email,
        'nickname' => reset($name_parts),
        'display_name' => $name,
        'first_name' => reset($name_parts),
        'last_name' => end($name_parts),    
        'role' =>  $role
    );

答案 1 :(得分:0)

试试这个, 获取数组外的角色值

$role = "";
$option = $_GET['I-would-like'];
$option = trim($option);
if ($option == 'A quotation' || $option == 'Information')
{
    $role = 'customer';
} else if($option == 'To become a Partner') 
{
    $role = 'partners';
} else if ($option == 'Training / Coaching')
{
    $role =  'students';
}


$userdata = array(
    'user_login' => $username,
    'user_pass' => $password,
    'user_email' => $email,
    'nickname' => reset($name_parts),
    'display_name' => $name,
    'first_name' => reset($name_parts),
    'last_name' => end($name_parts),    
    'role' => $role
);