Using preg_match as boolean AND array
Posted
by
silow
on Stack Overflow
See other posts from Stack Overflow
or by silow
Published on 2010-12-30T19:49:15Z
Indexed on
2010/12/30
19:53 UTC
Read the original article
Hit count: 135
php
|preg-match
I have this code where preg_match is used to break up a string into $pmarr
array. Index 1 of that array is then being used to set a value $val = $pmarr[1]
.
$pmarr = array();
if (preg_match($expression, $orig, $pmarr)) {
$val = $pmarr[1];
}
What I'm wondering about is why the preg_match itself is being used as a boolean. If the expression doesn't match, does the array stay empty and therefore equate to false?
Is the above code the same as saying
preg_match($expression, $orig, $pmarr);
if(isset($pmarr[1]) AND !empty($pmarr[1])){
$val = $pmarr[1];
}
© Stack Overflow or respective owner