这种情况FOREACH怎么用
foreach($str as $key=>$row)<br /> {<br /> if(preg_match_all('/\b[Nn][Ss][Kk]-\w{5}/',$sn,$match)){<br /> $str[$key]['darfon_pn']=substr_replace($match[0][0],$row['darfon_pn'],7,2);<br /> }else{<br /> $str[$key]['darfon_pn'] = '';<br /> }<br /> }
Copy after login
以上代码只遍历了$match[0][0],如何才能遍历整个$match每个值
------解决方案--------------------最初的 $str[$key]['darfon_pn'] 的内容是什么?
测试代码
$sn = 'NSK-34582 NSK-UUS89 NSK-89234';<br />preg_match_all('/\b[Nn][Ss][Kk]-\w{5}/',$sn,$match);<br />print_r($match[0]);<br />$str = '________';<br />foreach($match[0] as $v) {<br /> $str = substr_replace($v, $str,7,2);<br /> echo $str,PHP_EOL;<br />}<br />
Copy after login
Array
(
[0] => NSK-34582
[1] => NSK-UUS89
[2] => NSK-89234
)
NSK-345________
NSK-UUSNSK-345________
NSK-892NSK-UUSNSK-345________
是你期望的吗?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn