In this case, how does FOREACH use

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.