📜 ⬆️ ⬇️

play with logical operators

I just wanted to play around with logical operators, with assignment and do something really useful ...


My idea was born to make a function to which you can transfer parameters according to the scheme:
either a string, or a key / value pair, or just an array with a pair of values ​​...

code in color
dumpz.org/2626
')
... I wrote, I understood that I was never right and did it without distortions ... now you can simply transfer either 1 or 2 parameters to the function, that's all ...
I spent 10 minutes on it, I felt pained to play with logical operators ... maybe someone is interested in what NOT readable code it can spill out ... I'm sure that if you sit for half an hour, you can wind almost any complexity of monsters there ...
 function choise ($ index) {
	 $ types = array ("model", "brand");
	 if (
		 ! ((count ($ index) == 2 and in_array ($ type = $ index [0], $ types) and ($ id = is_int ($ index [1])? $ index [1]: 0 and! $ keyword = false or $ keyword = $ index [1] and! $ id = false))
		 or (count ($ index) == 1 and in_array ($ type = key ($ index), $ types) and (($ id = is_int (current ($ index))? current ($ index): 0 and! $ keyword = false) or ($ keyword = current ($ index) and! $ id = false)))
		 or ($ type = false or $ id = false or $ keyword = false))
	 ) {
		 echo 'incorrect format'. "\ n";
		 return;
	 }
	
	 echo '$ type =';
	 var_dump ($ type);
	 echo '$ keyword =';
	 var_dump ($ keyword);
	 echo '$ id =';
	 var_dump ($ id);
	 echo '-------------'. "\ n";
 }

 choise (array ('model' => 5));
 choise (array ('model', 5));
 choise (array ('model', 'bmw'));
 choise (array ('model' => 'bmw'));
 choise (array ('m' => 'bmw'));
 choise (array ('m', 'bmw'));
 choise (array ('model', 'bmw', 5));



Only these monsters will not understand anyone ...
they are given here so that everyone can see how unpleasant they can become from the side and before writing write. I share an expo - catch a freebie.

Source: https://habr.com/ru/post/40668/


All Articles