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
  • 30,030
  • 21
  • 100
  • 124
tread
  • 9,064
  • 16
  • 86
  • 149
  • 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
  • 86,267
  • 25
  • 136
  • 177