简体   繁体   中英

What does the logical OR do in following php code

if($post_id === null) {
    $this->db->insert($data);
    !isset($data[$this->page_id]) || $data[$this->page_id] = NULL;

}

Logical operators perform short-circuit evaluation . If the first part of a logical OR is true, the whole expression is true and hence, there is no need to evaluate the second part.

What it is doing is equivalent to:

if(isset($data[$this->page_id])){
    $data[$this->page_id] = NULL
}

To give an example of how this works, from the documentation :

// foo() will never get called as those operators are short-circuit
$a = (false && foo());
$b = (true  || foo());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM