3v4l.org

run code in 300+ PHP versions simultaneously
<?php function traverse($arr){ $result_2 = []; while (key($arr)) { $result_2[key($arr)] = current($arr); next($arr); } print_r($result_2); } $data = [ "k0"=>"v0", "k1"=>"v1", "k2"=>"v2", "k3"=>"v3", "k4"=>"v4", ]; traverse($data); $result_1 = []; while (key($data)) { $result_1[key($data)] = current($data); next($data); } print_r($result_1);
Output for 5.6.38 - 5.6.40, 7.0.33, 7.1.0 - 7.1.30, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.30, 8.0.0 - 8.0.20, 8.1.0 - 8.1.7
Array ( [k0] => v0 [k1] => v1 [k2] => v2 [k3] => v3 [k4] => v4 ) Array ( [k0] => v0 [k1] => v1 [k2] => v2 [k3] => v3 [k4] => v4 )

preferences:
39.69 ms | 410 KiB | 5 Q