2

Consider:

array (size=1)
  0 =>
    array (size=5)
      'name' => string '15268459735 Farming and Projects XXXXX' (length=38)
      'region' => string '2' (length=1)
      'entitynumber' => string '2012/002086/24' (length=14)
      'ownership' => string '6' (length=1)
      'id' => string '26249' (length=5)

Why does the following still return the same array without the owner element?

foreach ($result as $row)
{
    $row['owner'] = 1;
}
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
stephen
  • 7,825
  • 14
  • 77
  • 134
  • 2
    Because you don't change `$result`. You change only `$row` which contains a temporary copy of one item of `$result`. – axiac Dec 05 '15 at 22:54

1 Answers1

5

Try passing the array by reference:

foreach ($result as &$row) {
    $row['owner'] = 1;
}

See also: What's the & for, anyway?

Community
  • 1
  • 1
Blazemonger
  • 82,329
  • 24
  • 132
  • 176