Answer the question
In order to leave comments, you need to log in
How to write if else correctly?
Hello everyone, I have a question how to properly register the if else
check!
For example:
<?php
$a = 1;
// проверяем подходит ли переменная
if (empty($a)) {
echo "a = empty";
exit();
}else{
// если прошло то делаем заключительную проверку
if(is_integer($a)){
echo "это число";
exit();
}else{
echo "нееее";
exit();
}
}
?>
Answer the question
In order to leave comments, you need to log in
in php there is an elseif (condition) operator, with its help such code will look like this
if(empty($var)){
// code here...
}elseif(is_numeric($var)){
// another code here...
}else{
// and here
}
if(validate_text($text)){
$text_id_database = $db->select('some query here where text = '.$text);
if($text_in_database){
write_some_info();
}else{
$errors[] = 'some error';
}
}else{
$errors[] = 'Invalid text';
}
$a = 1;
if( empty($a) ){
echo "a = empty";
elseif(is_integer($a)){
echo "это число";
}else{
echo "нееее";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question