Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Ampersands Between Function Calls

Tags:

php

What do two ampersands separating function calls do? Note: this is OUTSIDE any if statement or case statement

Like so:

functionCallOne() && functionCallTwo();
like image 775
Charles Avatar asked Nov 09 '10 23:11

Charles


2 Answers

it is equivalent to

if ( functionCallOne() ) {
  functionCallTwo();
}

it just uses the short circuiting to make this 3 liner only take up one line

like image 121
tobyodavies Avatar answered Nov 17 '22 02:11

tobyodavies


That is the short-circuit AND operator, meaning the second function (or expression/statement) will only be evaluated if the first returns true.

like image 5
karim79 Avatar answered Nov 17 '22 01:11

karim79