简体   繁体   中英

Associative Array loop same value

I have an associative array where i put DomElements. I want just recovers a cell from a table so i loop the rows($materie) and i try to extract for each the 9 column cell. The problem is that the result of the $cell[$o][9]->nodeValue ( that i put on $DTO['materie'][$o]['prenotato']) is the same for each turn of the loop: it take the value of the first element and keep the same.

   for($o = 0; $o < sizeof($materie); $o++) {

        $DTO['materie'][$o] = $materie[$o+1];
        /**ROWS */

        $cell = array();
        $cell[$o] = $parserCommons->findElementsByTag($table[0], 'td');

        $DTO['materie'][$o]['prenotato'] = $cell[$o][9]->nodeValue; 

    }


    return $DTO;

this is the function body:

public function findElementsByTag($DOMArray, $tagName)
{
    $output = $DOMArray->getElementsByTagname($tagName);
    return $output;
}

The problem is the call ...

$cell[$o] = $parserCommons->findElementsByTag($table[0], 'td');

So it is always using $parserCommons as the start point to find the <td> tags. So this will always find the same set of fields.

If your rows are in $materie , then I think you need

$cell[$o] = $materie[$o+1]->findElementsByTag($table[0], 'td');

so that it uses the current row for the start point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM