Reputation: 601
I am having issues changing the values, of variables i have fetched from my MySQL database. I am trying this
foreach( $itemsCurrentSorted as $item ) {
echo "pre: " . $item[4];
$item[4] = 100;
echo "after: " . $item[4];
}
the itemsCurrentSorted contains results from fetching rows from a MySQL database. The weird thing is, that the echo statements gives me the proper result. It seems to change the value. HOWEVER, the second it starts on a new iteration, it is like the value was never reset anyways. So it doesn't keep the new value?
So i guess my question in short is: How do you change the value, in a row you fetched from a MySQL database. Thanks on advance
Upvotes: 0
Views: 52
Reputation: 5963
Try editing by reference
foreach ($key as &$value) {
}
The ampersand means it will make changes to the original array.
Upvotes: 1