大変、お世話になっております。
どうしても、解決しないため、度々で申し訳ございませんが、
質問をさせてください。
(最終的な目的)
$rockから得られる11115555から得られる計5つの配列を取得したいのですが、それぞれの$rockの要素は特徴があり、$swithによりcase13のいずれかに分類されます。具体的には以下の通りです。
case1->1111
case2->2222,3333
case3->4444,5555
(ご質問)
そこで質問ですが、コードの下部にあるように、まず試しに$combを出力しようと思ったのですが、PatternAの箇所(for文の外)では出力できて、PatternAの箇所(for文の外)では出力できません。実際にはfor文の外でそれぞれ5つの取得した配列を使用したいのですが、なぜPatternBでは出力できないのでしょうか?
(PatternBの結果はArray()と空の配列が帰ってきてしまいます。)
これが解消すれば最終的な目的である、PatternCが実現できるものと考えております。
$rock=array(1111,2222,3333,4444,5555); for ($p=0; $p <count($rock) ; $p++) { $url="http://XXXXXXXXX/".$rock[$p]."/XXXXX"; $html = file_get_contents($url); $html = mb_convert_encoding($html, mb_internal_encoding(), "auto" ); preg_match_all("/<th>(.*?X.*?)<\/th>/", $html,$matches0);// preg_match_all( "/\"num\">(.*?)<br \/>/", $html, $matches1); preg_match_all( "/<br \/><span class=\"group\">([0-9年月日()]+)<\/span>/", $html, $matches2); preg_match_all( "/\"num\">([0-9]+月)<\/td>/", $html, $matches3); preg_match_all( "/\"num\">([0-9,.%-]+)<\/td>/", $html, $matches4); // if ($rock[$p]!==4444) { array_splice($matches4[1],0,2);// } $matchesX=$matches0[1]; $matchesA=$matches1[1]; $matchesB=$matches2[1]; $matchesC=$matches3[1]; $matchesD=$matches4[1]; $counta=count($matchesX); echo "$counta"; // sleep(15); $comb = array(); $comb_1=array(); $comb_2=array(); switch ($counta) { case '1': for ($s=0; $s <=0 ; $s++) { $comb[$s]=array($matchesX[$s],$matchesA[$s],$matchesB[$s],$matchesC[$s],$matchesD[$s],$matchesD[$s+2], $matchesD[$s+4],$matchesD[$s+6],$matchesD[$s+8],$matchesD[$s+10],$matchesD[$s+12], $matchesD[$s+14],$matchesD[$s+16],$matchesD[$s+18],$matchesD[$s+20],$matchesD[$s+22], $matchesD[$s+24],$matchesD[$s+26],$matchesD[$s+28]);}break; case '2': for ($q=0; $q <=1 ; $q++) { $comb_1[$q]=array($matchesX[$q],$matchesA[$q],$matchesB[$q],$matchesC[$q],$matchesD[$q],$matchesD[$q+3], $matchesD[$q+6],$matchesD[$q+9],$matchesD[$q+12],$matchesD[$q+15],$matchesD[$q+18], $matchesD[$q+21],$matchesD[$q+24],$matchesD[$q+27],$matchesD[$q+30],$matchesD[$q+33], $matchesD[$q+36],$matchesD[$q+39],$matchesD[$q+42]); }break; case '3': for ($t=0; $t <=2 ; $t++) { $comb_2[$t]=array($matchesX[$t],$matchesA[$t],$matchesB[$t],$matchesC[$t],$matchesD[$t],$matchesD[$t+4], $matchesD[$t+8],$matchesD[$t+12],$matchesD[$t+16],$matchesD[$t+20],$matchesD[$t+24], $matchesD[$t+28],$matchesD[$t+32],$matchesD[$t+36],$matchesD[$t+40],$matchesD[$t+44], $matchesD[$t+48],$matchesD[$t+52],$matchesD[$t+56]);}break; }//switch //pattern B echo "<pre>"; print_r($comb); echo "</pre>"; }//for #pattern A echo "<pre>"; print_r($comb); echo "</pre>"; #pattern C echo "<pre>"; print_r($comb); echo "</pre>"; echo "<pre>"; print_r($comb_1); echo "</pre>"; echo "<pre>"; print_r($comb_2); echo "</pre>";
回答2件
あなたの回答
tips
プレビュー