For example I have the following function:
<?php
public function login($username, $password) {
if($condicao === 1) {
return true,
} elseif($condicao === 2) {
return 'qualquer string';
} else {
return false;
}
}
How do I use a function with 3 or more returns in this way, with two users like this:
if($login->login($username, $password)) {
echo 'foi';
} else {
echo 'não foi';
}
Did you understand?
EDITED
if (count($cookie) === 12) {
Session::set('ct0', $ct0[0]);
return true;
} elseif (count($cookie) === 13) {
return 'bloqued';
} else {
return false;
}
Let's suppose that the above example is a function made with curl
where if there is a correct login and password it returns true
, if the account is locked, it returns 'bloqued', if the inserted data is wrong it returns me false
;
Looking like this:
public function login($username, $password) {
curl...
if (count($cookie) === 12) {
return true;
} elseif (count($cookie) === 13) {
return 'bloqued';
} else {
return false;
}
}
// Modo de usar
if ($login->login($username, $password)) {
echo json_encode([
'error' => false,
'message' => 'Logado com sucesso, aguarde...'
]
);
} elseif($login->login($username, $password) !== true && $login->login($username, $password) !== false) {
echo json_encode([
'error' => true,
'message' => 'Conta bloqueada',
]
);
} else {
echo json_encode([
'error' => true,
'message' => 'Usuário e/ou Senha incorretos'
]
);
}