Question

I am using PHP, Zend and MySql.

I need to change the value of some rows in a result set. I tried using foreach but I found out that the changes won't persist outside the foreach block, and I couldn't find a way to get the result set's number of rows so I can use a for.

This is what I tried:

$datas = $this->getClientes($search);

    foreach ($datas as $row) {
        if($row['dt_pagamento'] != NULL && $row['valor_pago'] == NULL)
            $row['valor_pago'] = $this->PesquisaBoletoCorreto($row['id_parcela']);
}

getClientes returns a result set. PesquisaBoletoCorreto changes the result set's value.

Was it helpful?

Solution

Try this:

foreach ($datas as $key => $row) {
    if($row['dt_pagamento'] != NULL && $row['valor_pago'] == NULL)
        $datas[$key]['valor_pago'] = $this->PesquisaBoletoCorreto($row['id_parcela']);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top