如何缩短这行代码?

时间:2015-01-19 04:57:14

标签: php

我想问一下,我该如何缩短这段代码?

我已经尝试过ifelse,但我没有得到它..

我有这个

if (empty($data['current_password'])) {
        return false;
    }


    if (empty($data['new_password'])) {
        return false;
    }

    if ($data['new_password'] !== $data['new_password_again']) {
        return false;
    }

尝试

if () {
} elseif (empty($data['current_password'])) {
} elseif ($data['new_password'] !== $data['new_password_again']) {
}

但不起作用,请帮助

非常感谢

4 个答案:

答案 0 :(得分:1)

你可以这样做

if (empty($data['current_password']) || empty($data['new_password']) || $data['new_password'] !== $data['new_password_again']) 
{
    return false;
}

答案 1 :(得分:1)

如果你喜欢神奇的东西,试试这个

switch (true) {
    case (empty($data['current_password'])):
    case (empty($data['new_password'])):
    case ($data['new_password'] !== $data['new_password_again']):
    return false;
}

答案 2 :(得分:0)

这个?

return (empty($data['current_password']) || empty($data['new_password']) || $data['new_password'] !== $data['new_password_again']) ? false : '';

答案 3 :(得分:0)

尝试低于一,

return(empty($data['current_password'])||empty($data['new_password'])||$data['new_password'] !== $data['new_password_again']?FALSE:'');