I am trying to update only some values of an Array directly. Which is working perfectly. I am using the following method:
foreach( $items as &$item ) {
if( $criteria == 'correct' ) {
// update array
$item['update_me'] = 'updated';
}
}
So I now have an updated array called $items.
However, the problem I have, is when this Array is output to screen (via another foreach loop), the last row of the Array is missing.
If I print the entire array via the var_dump( $items ); method, I noticed that each row is prefixed with Array(9). Yet the last row is prefixed with &Array(9) – notice the leading ampersand. I’m sure this is significant! But I’m unsure what it means. Why is it only applied to the final row in the Array? And how do I get rid of it?
From comment:
array(6) {
[0]=> array(9) {
["item_id"]=> string(4) "1"
["item_description"]=> string(9) "blah blah"
["quantity"]=> string(1) "4"
["unit_cost"]=> string(4) "5.00"
["subtotal"]=> string(4) "20.00"
}
[1]=> &array(9) {
["item_id"]=> string(4) "2"
["item_description"]=> string(9) "blah blah"
["quantity"]=> string(1) "1"
["unit_cost"]=> string(4) "5.99"
["subtotal"]=> string(4) "5.99"
}
}
i think that’s not the nicest way to do this. i’d suggest doing it this way: