3v4l.org

run code in 300+ PHP versions simultaneously
<?php function insert_random_chars($str, $alphabet = "ABCDEFGHIJKLMNOPGRSTUVWXYZ") { // An array to hold the result $result = array(); // The highest character index in the string $max = strlen($alphabet) - 1; // Loop the characters in the input string foreach (str_split($str, 1) as $char) { // Add the current character and a random character to the output array array_push($result, $char, $alphabet[mt_rand(0, $max)]); } // Join the output array together return implode('', $result); } echo insert_random_chars("0123456789");

preferences:
31.05 ms | 402 KiB | 5 Q