3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arrays = json_decode('[ { "id": 0, "title": "a title" }, { "id": 1, "title": "another title" }, { "id": 2, "title": "one more title" } ]', true); $array = [ 'id' => 1, 'title' => 'a different title', ]; foreach ($arrays as &$value) { if ($value['id'] === $array['id']) { $value = $array; } } var_dump($arrays);
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.3.0beta1
array(3) { [0]=> array(2) { ["id"]=> int(0) ["title"]=> string(7) "a title" } [1]=> array(2) { ["id"]=> int(1) ["title"]=> string(17) "a different title" } [2]=> &array(2) { ["id"]=> int(2) ["title"]=> string(14) "one more title" } }