title: Problem with parse table in PHP - array_combine(): Both parameters should have an equal number of elements
body: <p><strong>Task:</strong> to extract any values ​​from the table by keys.</p>
  
  <p>A table can have any number of records.</p>
  
  <p><strong>Solution:</strong> I use DOC, foreach to translate the html code of the table into a data array.</p>
  
  <pre><code>    &lt;?php
    $text = '
    &lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
        &lt;table&gt;
          &lt;tr&gt;
            &lt;th&gt;Number&lt;/th&gt;
            &lt;th&gt;ID-A&lt;/th&gt;
            &lt;th&gt;ID-B&lt;/th&gt;
            &lt;th&gt;TAG&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;7&lt;/td&gt;
            &lt;td&gt;481&lt;/td&gt;
            &lt;td&gt;2&lt;/td&gt;
            &lt;td&gt;ABCSDE&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;2&lt;/td&gt;
            &lt;td&gt;125&lt;/td&gt;
            &lt;td&gt;1&lt;/td&gt;
            &lt;td&gt;XDFE&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/body&gt;
    &lt;/html&gt;
    ';
  
    $domdoc = new DOMDocument();
    $domdoc-&gt;loadHTML($text);
  
    $thArray = $tdArray = $array = array();
  
    // Get 'th' array
    $th = $domdoc-&gt;getElementsByTagName('th');
    foreach ($th as $th) {
      $thArray[] = $th-&gt;nodeValue;
    }
    $count = count($thArray);
    //echo var_dump($thArray);
  
    // Get 'td' array
    $td = $domdoc-&gt;getElementsByTagName('td');
    $i = 0;
    foreach($td as $td) {
      if(count($tdArray[$i]) != $count) {
        $tdArray[$i][] = $td-&gt;nodeValue;
      } else {
        $i++;
        $tdArray[$i][] = $td-&gt;nodeValue;
      }
    }
  
    $transactionArray = array_combine($thArray, $tdArray);
  
    echo var_dump($transactionArray);
  </code></pre>
  
  <p>The <strong>failure</strong> occurs at the stage of combining the array td and th.
  array_combine () requires that the number of records equal the number of rows in the table. If the number of records is equal to the number of cells to th, the error will disappear.</p>
  
  <pre><code>$transactionArray = array_combine($thArray, $tdArray);
  </code></pre>
  
  <p>In my case, the number of records can change in any direction.</p>
  
  <p><strong>Question:</strong> how in this case to unite arrays?</p>