- print_r: documentation ( source)
- preg_match_all: documentation ( source)
- array_shift: documentation ( source)
<?php
$re = '/^((?:(?!\<\?php echo[\s?](?:.*?)\;[\s?]\?\>).)*)<\?php echo[\s?](?:.*?)\;[\s?]\?\>(.*)/';
$str = 'customFields[<?php echo $field["id"]; ?>][type]';
preg_match_all($re, $str, $matches, PREG_SET_ORDER);
array_shift($matches[0]);
print_r($matches);