With the following if
hidden data if it exists or not from somesession
if(!$ticket) {
//No existe sesión
} else {
//Existe sesión
}
Now from a true data I need to be able to add two if
with true data (according to the received data) from its root if(!$ticket)
as follows:
if(!$ticket) {
//No existe sesión
} else {
if($operation==="extra"){
echo "tiene hora extra";
}
if($operation==="noextra"){
echo "no tiene hora extra";
}
}
can you explain me
The procedure that I am doing is correct or at the same time it is better to use aswitch
I am not so expert in programming, but I have never seen a similar procedure, can you explain to me if the procedure carried out is correct, I have always seen that when adding more
if
in oneelse
, it was done in this way:elseif
You can use a switch to not write the $operation variable you reference more than once.
Or an else if
else if() is usually used to refer to another test of the same variable. (In this case $operation). It could be changed to an if() if you were to check for a different variable.
elseif
as its name suggests, it is a combination ofif
andelse
.Just as it
else
extends a statementif
to execute a different statement in case theif
original expression evaluates toFALSE
.However, unlike
else
; that alternative expression will only be executed if the conditional expression ofelseif
evaluates toTRUE
.For example, the following code should return
a
is greater thanb
,a
is equal to ,b
ora
is less thanb
:elseif
within the same statementif
. The first expressionelseif
(if any) that is evaluated asTRUE
would be executed.In PHP it can also be written
else if
(in two words) and the behavior would be identical to that ofelseif
(in a single word). The syntactical meaning is slightly different (if you are familiar with C, this is the same behavior) but the bottom line is that they would both turn out to have exactly the same behavior.The statement
elseif
is executed only if theif
preceding expression and anyelseif
preceding expressions evaluateFALSE
to , and the current expressionelseif
evaluates toTRUE
.However the sentence
Switch
is defined:For instance
It is important to understand how the statement
switch
is executed in order to avoid errors. The statementswitch
executes line by line (actually, statement by statement). At first, no code is executed. Only when a statement is foundcase
whose expression evaluates to a value that matches the value of expressionswitch
, does PHP start executing the statement. PHP continues executing statements until the end of the blockswitch
, or until the first time it sees a statementbreak
.