In this case, how to use FOREACH & nbsp; foreach ($ str & nbsp; as & nbsp; $ key = & gt; $ row) & nbsp; & nbsp; {& nbsp; if (preg_match_all ('/\ B)
foreach($str as $key=>$row)
{
if(preg_match_all('/\b[Nn][Ss][Kk]-\w{5}/',$sn,$match)){
$str[$key]['darfon_pn']=substr_replace($match[0][0],$row['darfon_pn'],7,2);
}else{
$str[$key]['darfon_pn'] = '';
}
}
The above code only traverses $ match [0] [0]. how can we traverse every value of $ match?
------ Solution --------------------
What is the initial $ str [$ key] ['darfon _ pn?
Test Code
$sn = 'NSK-34582 NSK-UUS89 NSK-89234';
preg_match_all('/\b[Nn][Ss][Kk]-\w{5}/',$sn,$match);
print_r($match[0]);
$str = '________';
foreach($match[0] as $v) {
$str = substr_replace($v, $str,7,2);
echo $str,PHP_EOL;
}
Array
(
NSK-34582
NSK-UUS89
NSK-89234
)
NSK-345 ________
NSK-UUSNSK-345 ________
NSK-892NSK-UUSNSK-345 ________
What do you expect?