boolean - php preg_match() acts weirdly -


i found this, when i'm working in regex validation on php.

i've used preg_match function validate string.

i've printed value returned preg_match ensure working flow.

during i've found thing. can't understand concept.

that preg_match() returns 1 if match found. otherwise return 0. print function didn't print anything.

after gone through on php manual know of return value...

there posted follow...

preg_match() returns 1 if pattern matches given subject, 0 if not, or false if error occurred.

and used var_dump know printed or not...

this helped me know that's boolean false.

but i'm curious know why returns boolean false, when i'm putting " ! " (not) before preg_match()?

following code,

echo preg_match("/script/","script") // ===> returs 1  echo !preg_match("/script/","script") // ===> returns boolean false 

i think have return integer 0(zero)... me know functionality? or did wrong in syntax???

and 1 thing, i've tried in opencart 2.0.0.0 admin controller module.

the ! operator return boolean value.

for unary ! operator type of result bool. value of operand converted type bool , if true of operator result false, , result true otherwise.

langspec reference: https://github.com/php/php-langspec/blob/php-5.6/spec/10-expressions.md#unary-arithmetic-operators

the normal conversion rules bool applied value.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -