3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function by_tag($things) { $sorted = array(); foreach ($things as $thing) { $thing['title'] = "new title"; # this works! $thing['size'] = 100; # this doesn't work, it keeps the old value. array_push($sorted, $thing); } return $sorted; } $unsorted = array( array('foo' => 'bar', 'size' => 1, 'title' => 'changeme1'), array('foo' => 'bar', 'size' => 2, 'title' => 'changeme2'), array('foo' => 'bar', 'size' => 3, 'title' => 'changeme3'), array('foo' => 'bar', 'size' => 4, 'title' => 'changeme4'), array('foo' => 'bar', 'size' => 5, 'title' => 'changeme5') ); var_dump(by_tag($unsorted));
Output for 4.3.0 - 7.1.0
array(5) { [0]=> array(3) { ["foo"]=> string(3) "bar" ["size"]=> int(100) ["title"]=> string(9) "new title" } [1]=> array(3) { ["foo"]=> string(3) "bar" ["size"]=> int(100) ["title"]=> string(9) "new title" } [2]=> array(3) { ["foo"]=> string(3) "bar" ["size"]=> int(100) ["title"]=> string(9) "new title" } [3]=> array(3) { ["foo"]=> string(3) "bar" ["size"]=> int(100) ["title"]=> string(9) "new title" } [4]=> array(3) { ["foo"]=> string(3) "bar" ["size"]=> int(100) ["title"]=> string(9) "new title" } }