- preg_match: documentation ( source)
- print_r: documentation ( source)
<?php
$a = array( 'def9', 'abc7', 'cbd4' );
$b = array('r1' => '/abc\d/', 'b2' => '/cbd\d/', 'f5' => '/def\d/');
$result = array(); // Store the result
$iloop = 0; // Use to match corresponding element key in $a;
$matches = array();
foreach($b AS $key => $preg) {
if (preg_match($preg, $a[$iloop++], $matches)) {
$result[$key] = $matches[0];
}
}
print_r($result);