Am new to Regex & working through examples to clarify my understanding. PHP functions site gives an example for the preg_filter function, which I do understand fully - except for one thing:
$subject = array('1', 'a', '2', 'b', '3', 'A', 'B', '4');
$pattern = array('/\d/', '/[a-z]/', '/[1a]/');
$replace = array('A:$0', 'B:$0', 'C:$0');
gives for $replace
:
Array
(
[0] => A:C:1
[1] => B:C:a
[2] => A:2
[3] => B:b
[4] => A:3
[7] => A:4
)
So far so good - I understand why elements [5] & [6] aren't returned, & why elements [2] - [7] display the values they do. Where I get confused is with elements [0] & [1].
I was expecting return values of A:1C:1 & B:aC:a respectively, as each matched pattern is replaced with the 'capital letter:' & the capture referenced value.
So I am wondering what aspect of Regex (I'm still very new to this) I'm missing given the actual result displayed.
Any assistance would be gratefully received.
Thanks