Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

foreach loop overwriting all values with last key value

$
0
0

I have got an array from a database and I want to change some of the values like using ucwords() etc.

 

The problem is when i run the array through a foreach loop, it overwrites all the values in the array with the values of the last row in the array.

 

I've been racking my brains all afternoon and can't figure out what's going wrong.

foreach($rows as $key => $row) {

    //$rows['datetime'] = Forum::change_date(strtotime($row['postdate']));
    $rows[$key]['board'] = strtolower(str_replace(array(' ','\''), array('-',''),$row['boardname']));
    $rows[$key]['boardid'] = $row['boardno'];
    $rows[$key]['boardname'] = ucwords($row['boardname']);
    $rows[$key]['topicname'] = Words::shortenText($row['topicname'],30);
}

I end up with the 6 rows in the array all the same.

 

Any ideas what I'm doing wrong?


Viewing all articles
Browse latest Browse all 13200

Trending Articles