switch($matches[0][0])
does the trick. The extra index is necessary as a var_dump()
of $matches
reveals:
array(2) {
[0]=>
array(2) {
[0]=>
string(5) "test1"
[1]=>
int(0)
}
[1]=>
array(2) {
[0]=>
string(1) "1"
[1]=>
int(4)
}
}
As others point out, this is probably not the ideal way to solve the problem, though. There are many other ways, for example:
preg_match('/test([1-5]4])\./', $baseURL, $m);
return $m ? $m[1] + 1 : 1;