PHP conditions if elseif

-1

I'm developing an application in php and I want to determine if a certain word will receive the letter "a" or the letter "o".

I was doing with if and elseif , but I do not know why it is not working.

I will put an example that I did to demonstrate my problem, this is not the code of my application, but it is an example that explains my problem well.

$type = "";
$texto1 = "carr";
$texto2 = "cas";

if($texto1){
$type = "o";
}elseif($texto2){
$type = "a";
}
echo $texto1.$type . '<br>';
echo $texto1.$type;
    
asked by anonymous 03.08.2018 / 18:42

1 answer

0

The constructor if has the return of type booleano , that is, it tests whether the condition is verdadeira or falsa . So your code is testing whether the $texto1 variable is true, and since it is not empty, the return will always be true .

Take a look at the control structures of php :

link

    
08.08.2018 / 13:06