Re: Short writage of clauses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Barry wrote:
> Stut schrieb:
>> Barry wrote:
>>> Well i do know that you can write IF as ( ? : ) but what i am asking
>>> about is something like this:
>>>
>>> if (a = 1 OR a = 2)
>>
>> I think you mean == not =.
> Yeah. sorry ;)
>>
>>> is it anyway possible to write it like:
>>> if (a = 1 OR 2)
>>>
>>> I know this is wrong because "2" will always be true ...
>>>
>>> Any infos on that would be nice :)
>>
>> The only way I know of to do this sort of thing would be...
>>
>>    if (in_array($a, array(1, 2)))
> Hmm yes this is actually a shorter way.
> 
> But it has limits hasn't it?
> if (in_array(a, array(date("d",time),CONSTANT_NAME,function_call())))
> 
> Like that
> 
>>
>> But it begs the question why you would want to do this?
> 
> Oh, uhm well something like this probably:
> If the age of my grandma is as old as the age of the table, lower than
> the age the house was build, equal to the summary of ages from the
> grandchilds, bigger than 50 but not higher than 70 AND only when she is
> as old as me i do have to bake a cookie

I find a switch statement sometimes handy for creating a 'truth table'
like you describe (I sometimes find it easier to read and/or add 'if' clauses):

switch (true) {
	case ($grandmaAge >= $tableAge):
	case ($grandmaAge < $houseAge):
	case ($grandmaAge == array_sum($grandKids)):
		bakeCookie();
		break;
	default:
		haveABeer();
		watchFootball();
}

functionally the above could just as well be an if statement - it's pretty much
a question of personal preference.

> 
> Something like that.
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux