3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [['el1','el2'],['el3','el4'],]; function add_el($data,$elem){ foreach($data as $ind=>&$ar){ $ar[] = $elem; } return $data; } $el = 'el new'; print_r(add_el($data,$el));
based on VFcQp
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.24, 7.4.0 - 7.4.12, 8.0.0
Array ( [0] => Array ( [0] => el1 [1] => el2 [2] => el new ) [1] => Array ( [0] => el3 [1] => el4 [2] => el new ) )