插入数组

I want to get out of every 3 cells The first cell with index 0, the second 1, the third 2 And bring it all into an array so that in the $ result [0] were all cell values ​​at index 0 - all tr lines, etc.

<?
$lines = $xpath->query("//table[@id='cab_table'] //tr");
            $result = array();

                foreach($lines as $line) {

                    for($j=0; $j<=3; $j++) {

                     $tds_{$j} = $xpath->query('//td['.$j.']', $line);
                     $tds_{$j} = $xpath->query('//td['.$j.']', $line);
                     $tds_{$j} = $xpath->query('//td['.$j.']', $line);

                     $count = $tds_{$j}->length;

                        for($i=0; $i<$count; $i++){

                            $result['number'][] = $tds_{$j}->item($i)->nodeValue;
                            $result['volume'][] = $tds_{$j}->item($i)->nodeValue;
                            $result['code'][] = $tds_{$j}->item($i)->nodeValue;

                        }

                    }

?>              }

HTML code:

        <div class="pc-data-cab_table_block_container" style="overflow:auto">
            <div id="cab_table_block" style="width:100%;overflow:auto">
                <table id="cab_table" cellpadding="0px" cellspacing="0px" style="width:100%;overflow:auto">
                    <tr id="cab_table_tr_top">
                        <th id="cab_table_left">Номер счета</th>
                        <th>Объем</th>
                        <th id="cab_table_right">РЎСѓРјРјР° РєРѕРјРјРёСЃСЃРёРё</th>
                    </tr>
                                                                                <tr class="cab_table_tr2">
                            <td class="cab_table_left1">510169</td>
                            <td style='width:130px'>0.04</td>
                            <td class="cab_table_right1">2.07</td>
                         </tr>
                                                                                    <tr class="cab_table_tr1">
                            <td class="cab_table_left1">1193683</td>
                            <td style='width:130px'>0.23</td>
                            <td class="cab_table_right1">0.00</td>
                         </tr>
                                                                                    <tr class="cab_table_tr2">
                            <td class="cab_table_left1">2159860</td>
                            <td style='width:130px'>1.06</td>
                            <td class="cab_table_right1">51.54</td>
                         </tr>
                                                                                    <tr class="cab_table_tr1">
                            <td class="cab_table_left1">8070080</td>
                            <td style='width:130px'>1.76</td>
                            <td class="cab_table_right1">147.80</td>
                         </tr>
                                                                                    <tr class="cab_table_tr2">
                            <td class="cab_table_left1">8079297</td>
                            <td style='width:130px'>19.25</td>
                            <td class="cab_table_right1">884.85</td>
                         </tr>
                                                                            </table>
            </div>
        </div>

This is my solution, if you can, modify it

foreach($lines as $num => $line) { 


                            $new1 = $xpath->query('//td[1]', $line);
                            $new2 = $xpath->query('//td[2]', $line);
                            $new3 = $xpath->query('//td[3]', $line);

                            foreach ($new1 as $value) {

                                $result['number'][$value->nodeValue] = $value->nodeValue;

                            }

                            foreach ($new2 as $value) {

                                $result['volume'][$value->nodeValue] = $value->nodeValue;

                            }

                            foreach ($new3 as $value) {

                                $result['code'][$value->nodeValue] = $value->nodeValue;

                            }


                }

What about having a single XPath expression and looping in 3-tuples?

$cells = $xpath->query('//td');

for($i=0; $i<$cells->length; ) {
  $result['number'][] = $cells->item($i++)->nodeValue;
  $result['volume'][] = $cells->item($i++)->nodeValue;
  $result['code'][] = $cells->item($i++)->nodeValue;
}