Collect or compare variables in PHP

1

I have some PHP variables, which are these:

<?php
$on = "ON";
$off = "OFFLINE";
$disabled ="disabled";
?>

Well, what I want to do is a bit more automatic, if I use the variable " $off " automatically in another sector the variable " $disabled " is added.
And if it is in " $on " do not put anything.
The "disabled" is within a " class="" " in an HTML tag.

And here would have to go the Off / On
<div id="lideres-jugador-header"> <?php echo "$off"; ?> </div>

And here I would go if it is disabled or not at all:
<a href="/link/" class="waves-effect waves-light btn <?php echo "$disabled"; ?>"> <font color="#FFFFFF">VER</font></a>

    
asked by MatiST00 05.12.2018 в 00:11
source

2 answers

0

I think you should put all the code of what you are trying to do, but I will try to give you an answer with the information you give.

First, create variables that are preferably Boolean.

$switch = true; // Si es true seria el equivalente para On y false para Off
$state = true; // Si es true seria el equivalente para Enabled y false para Disabled

and a third for the exit

$print = "";

Now I do not understand the sectors, but I think what you need is an if

if(!$switch) 
{
    if(!$state)
    {
        $print = 'Off/Disabled';
    }

} else {
    $print = '';
}
    
answered by 05.12.2018 в 00:24
0

Even though it is not entirely clear what you want, I think this may be one of the cases in which variable variables of php can be applied

Example:

// defines los valores a mostrar
$on = "ON";
$off = "OFFLINE";
$disabled ="disabled";

// defines el estado que quieres mostrar
// debe coincidir con el nombre de alguna variable
$estado = 'on';

// muestra con variable variable
echo $$estado; // ON

// cambiamos el valor del estado
$estado = 'off';
echo $$estado; // OFFLINE

Note the double use of $$ in

echo $$estado;

Documentation: link

I have to say that this can make the code little readable and can lead to chaos that can not be understood, if it is not used properly.

    
answered by 05.12.2018 в 12:00