I like to use a php function to switch between ON and OFF automatically upon the call. Of course something simple like $condition="OFF"; switch ($condition) { case "OFF" : $condition="ON"; break; case "ON" : $condition="OFF"; break; } this always returns ON but that is not what I need. How can I make it so that it remember the previous setting of $condition and act accordingly so it alternate between ON/Off automatically upon the call to the function? Thanks
Maybe you can store the last value (ON or OFF) in a session variable. session_start(); $_SESSION['last_state'] = 'OFF'; switch ($_SESSION['last_state']) { case "OFF" : $_SESSION['last_state']="ON"; break; case "ON" : $_SESSION['last_state']="OFF"; break; } PHP:
GOD O GOD Why SWITCH FOR ONLY 2 PARAMETERS? $_SESSION['last_state'] = ($_SESSION['last_state'] == 'OFF') ? 'ON' : 'OFF'; To easy