Using preg_match as boolean AND array
- by silow
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];
}