3v4l.org

run code in 300+ PHP versions simultaneously
<?php function passwordCreate ($length = 8, $mode = '12345') { $small = 'abcdefghijklmnopqrstuvwxyz'; $large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $numeric = '0123456789'; switch ($mode) { // 小文字英字 case 'small': $chars = $small; break; // 大文字英字 case 'large': $chars = $large; break; // 小文字英数字 case 'smallalnum': $chars = $small . $numeric; break; // 大文字英数字 case 'largealnum': $chars = $large . $numeric; break; // 数字 case 'num': $chars = $numeric; break; // 大小文字英字 case 'alphabet': $chars = $small . $large; break; // 大小文字英数字 case 'alnum': default: $chars = $small . $large . $numeric; break; } $charsLength = strlen($chars); $password = ''; for ($i = 0; $i < $length; ++$i) { $num = mt_rand(0, $charsLength - 1); $password .= $chars{$num}; } return $password; }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.24, 7.3.0 - 7.3.12

preferences:
236.15 ms | 404 KiB | 318 Q