PHP - toggle state

Nykus

New Member
The problem is simple, but I'm looking for a creative solution.We meet very often arrays, objects that has a property that can be toggled (it can be active or inactive, 1 or 0).What I want is a creative solution (a function) to transform 0 to 1, and 1 to 0.Some examples:\[code\]// Firstif ($state == 1){ $state = 0;}else{ $state = 1; }// Second$states = array(1, 0);$state = $states[$state];// Third$state = ($state == 1) ? 0 : 1;\[/code\]Is there another, one line solution for this?Thanks, and enjoy the brainstorming.
 
Top