3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mod(&$item){ $item["position"] = preg_replace("/[^0-9]+/","",$item["position"]); $item["count"] = 2*$item["count"]; } $items = [ ["position" => "1", "count" => 4], ["position" => "2", "count" => 3], ]; echo "before: \n"; foreach($items as $item){ var_dump($item) . "\n"; } echo "modifying items...\n"; foreach($items as &$itemRef){ mod($itemRef); } echo "after: \n"; foreach($items as $item){ echo "A"; var_dump($item) . "\n"; }
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
before: array(2) { ["position"]=> string(1) "1" ["count"]=> int(4) } array(2) { ["position"]=> string(1) "2" ["count"]=> int(3) } modifying items... after: Aarray(2) { ["position"]=> string(1) "1" ["count"]=> int(8) } Aarray(2) { ["position"]=> string(1) "2" ["count"]=> int(6) }

preferences:
157.38 ms | 408 KiB | 5 Q