User Tools

Site Tools


programmieren:grundlagen:logical_operators

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
programmieren:grundlagen:logical_operators [2026/11/06 16:25] – created adminprogrammieren:grundlagen:logical_operators [2026/11/12 16:36] (current) – Added Types and Array admin
Line 44: Line 44:
 </code> </code>
  
-I should totally expand this list+===== Comparison ===== 
 + 
 +<code php> 
 +// Is equal 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a == $b; // False 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a == $b; // True 
 + 
 +$a = 1; 
 +$b = true; 
 + 
 +$a == $b; // True 
 + 
 +// Is identical 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a === $b; // False 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a === $b; // True 
 + 
 +$a = 1; 
 +$b = true; 
 + 
 +$a === $b; // False 
 + 
 +// Is not equal 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a != $b; // True 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a != $b; // False 
 + 
 +$a = 1; 
 +$b = true; 
 + 
 +$a != $b; // False 
 + 
 +// Is not identical 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a !== $b; // True 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a !== $b; // False 
 + 
 +$a = 1; 
 +$b = true; 
 + 
 +$a !== $b; // True 
 + 
 +// Is less than 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a < $b; // False 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a < $b; // False 
 + 
 +$a = 30; 
 +$b = 50; 
 + 
 +$a < $b; // True 
 + 
 +// Is greater than 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a > $b; // True 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a > $b; // False 
 + 
 +$a = 30; 
 +$b = 50; 
 + 
 +$a > $b; // False 
 + 
 +// Is less than or equal to 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a <= $b; // False 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a <= $b; // True 
 + 
 +$a = 30; 
 +$b = 50; 
 + 
 +$a <= $b; // True 
 + 
 +// Is greater than or equal to 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a >= $b; // True 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a >= $b; // True 
 + 
 +$a = 30; 
 +$b = 50; 
 + 
 +$a >= $b; // False 
 + 
 +// Spaceship???, returns an int indicating if value is bigger, smaller or equal to other value 
 + 
 +$a = 50; 
 +$b = 30; 
 + 
 +$a <=> $b; // 1 
 + 
 +$a = 50; 
 +$b = 50; 
 + 
 +$a < $b; // 0 
 + 
 +$a = 30; 
 +$b = 50; 
 + 
 +$a < $b; // -1 
 + 
 +</code> 
 + 
 +===== Logical ===== 
 + 
 +<code php> 
 +$a = true; 
 +$b = false; 
 + 
 +$a and $b // False 
 + 
 +$a or $b // True 
 + 
 +$a xor $b // True 
 + 
 +$a && $b // False 
 + 
 +$a || $b // True 
 + 
 +$a = true; 
 +$b = true; 
 + 
 +$a and $b // True 
 + 
 +$a or $b // True 
 + 
 +$a xor $b // False 
 + 
 +$a && $b // True 
 + 
 +$a || $b // True 
 + 
 +$a = false; 
 +$b = false; 
 + 
 +$a and $b // False 
 + 
 +$a or $b // False 
 + 
 +$a xor $b // False 
 + 
 +$a && $b // False 
 + 
 +$a || $b // False 
 + 
 +// Symbols take presedence over words 
 + 
 +</code> 
 + 
 +===== String ===== 
 + 
 +<code php> 
 + 
 +// Concatenation 
 + 
 +$a = 'Foo'; 
 +$b = 'bar'; 
 + 
 +$a = $a . $b; // $a = 'Foobar' 
 + 
 +// Assignment 
 + 
 +$a .= $b; // $a = 'Foobar' 
 + 
 +</code> 
 + 
 +===== Array ===== 
 + 
 +<code php> 
 +// Union 
 + 
 +$a = ["a" => "apple", "b" => "banana"]; 
 +$b = ["a" => "pear", "b" => "strawberry", "c" => "cherry"]; 
 + 
 +$c = $a + $b; // $c = ["a" => "apple", "b" => "banana", "c" => "cherry"]. Any keys that already exist in the previous array are ignored 
 +</code> 
 + 
 +===== Types ===== 
 + 
 +<code php> 
 +// instanceof 
 + 
 +class ParentClass {} 
 +class MyClass extends ParentClass {} 
 +class NotMyClass {} 
 + 
 +$a = new MyClass; 
 +$b = new NotMyClass; 
 +$c = new ParentClass; 
 + 
 +$a instanceof MyClass // True 
 +$a instanceof NotMyClass // False 
 +$a instanceof ParentClass // True, works with any kind of inheritance 
 + 
 +$b instanceof MyClass // False 
 +$b instanceof NotMyClass // True 
 +$b instanceof ParentClass // False 
 + 
 +$c instanceof MyClass // False 
 +$c instanceof NotMyClass // False 
 +$c instanceof ParentClass // True 
 + 
 +</code>
  
programmieren/grundlagen/logical_operators.1793978707.txt.gz · Last modified: by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki