如何将增量名称变量放入循环

时间:2019-03-30 11:21:15

标签: php

我不是程序员,但是我必须对自己的网站进行一些工作。

请告诉我怎么做

注释代码中的问题。

<?php
 for ($o = 1; $o < 9 ; $o++) {
$file = '/patch/to/file_'.$o.'.xml';

 $doc = new DOMDocument();
 $doc->load($file);
 $destinations = $doc->getElementsByTagName("model");
 foreach ($destinations as $destination) {
    foreach($destination->childNodes as $child) {
        if ($child->nodeType == XML_CDATA_SECTION_NODE) {

            ${'czy' . $o}[] = $child->textContent;
          }
      }
   }

}


$merge = array_merge($czy1, $czy2, $czy3, $czy4, $czy5, $czy6, $czy7, $czy8);
// How do this?? but in loop function (from $czy1 to $czy8)?






1 个答案:

答案 0 :(得分:1)

 for ($o = 1; $o < 9 ; $o++) {
$file = '/patch/to/file_'.$o.'.xml';

 $result = [];

 $doc = new DOMDocument();
 $doc->load($file);
 $destinations = $doc->getElementsByTagName("model");
 foreach ($destinations as $destination) {
    foreach($destination->childNodes as $child) {
        if ($child->nodeType == XML_CDATA_SECTION_NODE) {

            $result = array_merge($result, $child->textContent);
          }
      }
   }

明白我的提示现在意味着什么吗?