-3

Please explain the following code. I can't understand what is happening.

return !$test
phpguest
  • 786
  • 1
  • 6
  • 16

2 Answers2

6

It returns the opposite boolean value of $test. If test is true, or anything that equates to true, it returns false. If it is false, or anything that equates to false, it returns true.

John Conde
  • 217,595
  • 99
  • 455
  • 496
2

The "!" is the 'NOT' operator.

the "return !$test" check the variable is not true (false). If $test is false then return true.

Ex: !$a >>>> TRUE if $a is not TRUE.

http://www.php.net/manual/en/language.operators.logical.php

jonasdiel
  • 36
  • 1