the AND operator in PHP

Im trying to improve my coding ninja h4x skills, and im currently looking at different frameworks, and i have found a sample of code, thats pretty hard to google.

I am looking at the FUEL framework used in a projectthe project can be found at https://github.com/ccschmitz/short-sale-management

the sample i dont understand is

$data and $this->template->set_global($data);

What is the et keyword doing in this line of code? It is used many places in the framework and its the first that i have found that uses it

Cette entrée a été publiée dans Non classé et étiquetés , , . Ajouter aux favoris permalink.

4 Les réponses à the AND operator in PHP

  1. wes dit:

    when you use logical operators, operands (the value on the left and the value on the right) are evaluated as boolean, so basically that code will do this, in a shorter way:

    $o1 = (Bool)$data; // cast to bool
    if($o1)
        $o2 = (Bool)$this->template->set_global($data); // cast to bool
    

    edit:

    some additional infos:

    $a = 33;
    isset($a) && print($a) || print("not set");
    echo "<br>";
    isset($a) AND print($a) OR print("not set");
    echo "<br>";
    

    try to comment/decomment $a = 33;
    this is the difference between && and AND, and between || and OR (print returns true that is casted to “1″ when converted to string)

  2. Matt Williamson dit:

    PHP supports both && et and for the logical AND operation, and they generally work identically, except and has a slightly lower operator precedence than &&: http://php.net/manual/en/language.operators.precedence.php

  3. wes dit:

    When you use logical operators, operands (the value on the left and the value on the right) are evaluated as boolean, so basically that code will do this, in a shorter way:

    $o1 = (Bool)$data; // cast to bool
    if($o1)
        $o2 = (Bool)$this->template->set_global($data); // cast to bool
    

    Edit:

    Some additional information:

    $a = 33;
    isset($a) && print($a) || print("not set");
    echo "<br>";
    isset($a) AND print($a) OR print("not set");
    echo "<br>";
    

    Try to comment/decomment $a = 33;. This is the difference between && et AND, and between || et OR (print returns true that is casted to “1″ when converted to string).

  4. Tom dit:

    When you use logical operators, operands (the value on the left and the value on the right) are evaluated as boolean, so basically that code will do this, in a shorter way:

    $o1 = (Bool)$data; // cast to bool
    if($o1)
        $o2 = (Bool)$this->template->set_global($data); // cast to bool
    

    Edit:

    Some additional information:

    $a = 33;
    isset($a) && print($a) || print("not set");
    echo "<br>";
    isset($a) AND print($a) OR print("not set");
    echo "<br>";
    

    Try to comment/decomment $a = 33;. This is the difference between && et AND, and between || et OR (print returns true that is casted to “1″ when converted to string).

Laisser un commentaire

Votre adresse email ne sera pas publié. Les champs obligatoires sont marqués *

Vous pouvez utiliser ces HTML balises et les attributs: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>