3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keys = ['1', '6', 4, '8', 'f', 200, '-1']; $one = []; foreach ($keys as $k) { $one[$k] = 'set'; } $two = []; foreach ($keys as $k) { $two[(int)$k] = 'set'; } var_dump($one, $two);
Output for 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 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.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
array(7) { [1]=> string(3) "set" [6]=> string(3) "set" [4]=> string(3) "set" [8]=> string(3) "set" ["f"]=> string(3) "set" [200]=> string(3) "set" [-1]=> string(3) "set" } array(7) { [1]=> string(3) "set" [6]=> string(3) "set" [4]=> string(3) "set" [8]=> string(3) "set" [0]=> string(3) "set" [200]=> string(3) "set" [-1]=> string(3) "set" }

preferences:
75.75 ms | 409 KiB | 5 Q