Ignore multiple conditions in PHP

3

I have the following doubt I have an if q if it is a process shows some things but if it is any other shows other things. To the naked eye like this:

<?php

if($proceso == 'Tp'){
    echo "Todo esto que ve TP";
}
else{
   echo "Todas estas cosas que ven los otro";
}

?>

How can I add a process that sees what it sees 'Tp' and what others see, that Tp sees the Tp, the others see their things and that new specific process sees what everyone sees and what they see. others?

Is it with an if or do I have to use a switch?

Case 1 ve esto
Case 2 ve esto
Default Case 1 Case 2

I did not find it but I can put a case to see what other Case's see and what default to ring the case 1 and case 2?

If it looks bad, I'm sorry from a celu and I do not see if it fits well what is code.

    
asked by Juan 05.07.2017 в 23:14
source

1 answer

2

Something like what you propose, using switch , would be a bit tedious, because if we remove the sentence break , after each case , we can execute the following sections up to default .

An example of this would be:

<?php

$variable = "Tp";

switch($variable){

   case "valor":
    echo "Aqui el valor\n";

   case "Tp":
    echo "He aqui Tp\n";

   case "Nada":
    echo "Un case mas\n";

   default:
    echo "Default presente\n";

}

?>

What we have done is remove all statements break , which allows that of a case , jump to the other, ignoring if the condition is fulfilled or not .

What is the problem?

Short answer: Conditions prior to the value we are evaluating are ignored.

What will give us as a result:

He aqui Tp
Un case mas
Default presente

Ignoring the condition:

case "valor":
    echo "Aqui el valor\n";

Solution

The solution, more approximate to what you are looking for, will be to do something like this:

<?php

$variable = "dos";

switch($variable){

   default:
    case1();
    case2();
    case3();

}


function case1(){
    echo "Case UNO\n";
}

function case2(){
    echo "Case DOS\n";
}

function case3(){
    echo "Case TRES\n";
}


?>

What we have done is to summarize the processes of case in functions and execute them all in default .

In this way, reusing, we would obtain as a result:

Case UNO
Case DOS
Case TRES
    
answered by 05.07.2017 / 23:50
source