{"id":522,"date":"2022-12-01T09:36:07","date_gmt":"2022-12-01T09:36:07","guid":{"rendered":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/?p=522"},"modified":"2022-12-01T09:53:44","modified_gmt":"2022-12-01T09:53:44","slug":"logical-operators","status":"publish","type":"post","link":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2022\/12\/01\/logical-operators\/","title":{"rendered":"Logical operators"},"content":{"rendered":"\n<p><br>If you haven\u2019t used them before, logical operators may at first seem a little daunting.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\" style=\"flex-basis:100%\">\n<pre class=\"wp-block-preformatted\">Operator     Description         Example\n&amp;&amp;           And                 $j == 3 &amp;&amp; $k == 2\nand          Low-precedence and  $j == 3 and $k == 2\n||           Or                  $j &lt; 5 || $j > 10\nor           Low-precedence or   $j &lt; 5 or $j > 10\n!            Not !               ($j == $k)\nxor          Exclusive or        $j xor $k<\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>Note that &amp;&amp; is usually interchangeable with and; the same is true for || and or. However, because and and or have a lower precedence you should avoid using them except when they are the only option, as in the following statement, which must use the or operator (|| cannot be used to force a second statement to execute if the first fails):<br><br><strong>$html = file_get_contents($site) or die(&#8220;Cannot download from $site&#8221;);<\/strong><br><\/p>\n\n\n\n<p>The most unusual of these operators is xor, which stands for exclusive or and returns a TRUE value if either value is TRUE, but a FALSE value if both inputs are TRUE or both inputs are FALSE. To understand this, imagine that you want to concoct your own cleaner for household items. Ammonia makes a good cleaner, and so does bleach, so you want your cleaner to have one of these. But the cleaner must not have both,<br>because the combination is hazardous. In PHP, you could represent this as follows:<\/p>\n\n\n\n<p><strong>$ingredient = $ammonia xor $bleach;<\/strong><\/p>\n\n\n\n<p>In this example, if either $ammonia or $bleach is TRUE, $ingredient will also be set to TRUE. But if both are TRUE or both are FALSE, $ingredient will be set to FALSE.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you haven\u2019t used them before, logical operators may at first seem a little daunting. Operator Description Example &amp;&amp; And $j == 3 &amp;&amp; $k == 2 and Low-precedence and $j == 3 and $k == 2 || Or $j &lt; 5 || $j > 10 or Low-precedence or $j &lt; 5 or $j > &hellip; <a href=\"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2022\/12\/01\/logical-operators\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Logical operators<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/522"}],"collection":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=522"}],"version-history":[{"count":6,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":537,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/522\/revisions\/537"}],"wp:attachment":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}