问题很简单,但我正在寻找一个创造性的解决方案。我们经常遇到数组,对象具有可以切换的属性(它可以是活动的或非活动的,1 或 0)。
我想要的是一个创造性的解决方案(一个函数),将 0 转换为 1,将 1 转换为 0。
一些例子:
// First
if ($state == 1)
{
$state = 0;
}
else
{
$state = 1;
}
// Second
$states = array(1, 0);
$state = $states[$state];
// Third
$state = ($state == 1) ? 0 : 1;
是否有另一种单线解决方案?谢谢,享受头脑风暴。