Register for your free account! | Forgot your password?

Go Back   elitepvpers > Blogs > manulaiko3.0
You last visited: Today at 17:55

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Rate this Entry

Programming in PHP - Logical Operators

Posted 01/30/2015 at 16:04 by manulaiko3.0

Copy and paste from my website:

In the last chapter we’ve seen maths, now we’re going to talk about logic.
Logic operators takes two booleans and returns another boolean (or takes two integers and returns one boolean, or takes two integers and returns anther integer :S)
Without talking more shit we’re going to touch logic operators right now!
And

Some times you will need to compare two things:
I want a red AND big car
If the car is red and big you’ll buy it, but if the car is red and small or green and big you won’t buy it, you want a fucking big red car!
So, how is this translated to PHP?
<?php $red = true; $big = false; $car = $red && $big; ?> This code will return false, why?
Because you want a fucking big and red car, not a red car. To make the variable $car true we have to modify the code to this:
<?php $red = true; $big = true; $car = $red && $big; ?> Now yes, it’s tre, you’ll buy it!!
Here’s a table so you can see the combinations:
Operator 1 Operator 2 Result true true true false true false true false false false false false OR

You’ve realized that the big and red car is too expensive for your pocket, what you can do?
You can get more money (drugs) or rethink what you want (a part from drugs):
I want a red OR big car
The red and big car is really expensive, but a red car or a big car isn’t so expensive. Let’s see how to implement this on PHP:
<?php $red = true; $big = false; $car = $red || $big; //true! ?> So, the or (||) operator returns true if any of the operator is true.
Here’s a table so you can see the combinations:
Operator 1 Operator 2 Result true true true false true true true false true false false false Not

Now you don’t want a red car, you want a green car (peace on you):
I want a not red car, I don’t give a fuck if it’s big or small
And here’s the code in PHP:
<?php $red = true; $car = !$red; //false ?> Bassically, the not (!) operator inverts the value given.
Here’s a table so you can see the combinations:
Operator 1 Result true false false true And it’s done, now you know what are logical operators, the next chapter I’ll talk about Comparation Operators
See you!
Posted in Uncategorized
Views 332 Comments 0 Email Blog Entry
« Prev     Main     Next »
Total Comments 0

Comments

 

All times are GMT +1. The time now is 17:56.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.