すごいです
上記のコードは $match[0][0] のみを走査しますが、$match 全体の各値をどのように走査することができますか?
$str[$key][ 'darfon_pn'] =substr_replace($match[$key][0],$row['darfon_pn'],7,2);
$str[$key]['darfon_pn']=substr_replace($match[0] ][ $key ],$row['darfon_pn'],7,2);
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'] = ''; } }
if(preg_match_all('/\b[Nn][Ss][Kk]-\w{5}/',$sn,$match)) { //由于$sn是另外的变量,没有必要放在循环里多次检查 foreach($match[0] as $v) { //对于每一个匹配到的串 foreach($str as $key=>$row) { //修改$str $str[$key]['darfon_pn'] = substr_replace($v, $row['darfon_pn'],7,2); } }}else{ //否则 foreach($str as $key=>$row) { $str[$key]['darfon_pn'] = ''; //赋空值 }}
最初の $str[$key]['darfon_pn'] とは何ですかの内容 ?
テストコード
if(preg_match_all('/\b[Nn][Ss][Kk]-\w{5}/',$sn,$match)) { //由于$sn是另外的变量,没有必要放在循环里多次检查 foreach($match[0] as $v) { //对于每一个匹配到的串 foreach($str as $key=>$row) { //修改$str $str[$key]['darfon_pn'] = substr_replace($v, $row['darfon_pn'],7,2); } }}else{ //否则 foreach($str as $key=>$row) { $str[$key]['darfon_pn'] = ''; //赋空值 }}
最初の $str[$key]['darfon_pn'] の内容は何ですか?
テストコード
$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;}
最初の $str[$key]['darfon_pn'] の内容は何ですか?
テストコード
$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;}