Skip to content

Instantly share code, notes, and snippets.

@podlom
Last active September 8, 2023 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podlom/2e6ab76fc1ca50528b941879e52402dd to your computer and use it in GitHub Desktop.
Save podlom/2e6ab76fc1ca50528b941879e52402dd to your computer and use it in GitHub Desktop.
Random strings generation
<?php
$randomCode = '';
define('STR_LEN', 8);
$characters = array_merge(range('a', 'z'), range(0, 9));
// echo 'The $characters: ' . var_export($characters, true) . PHP_EOL;
shuffle($characters);
// echo 'all shuffled characters: ' . var_export($characters, true) . PHP_EOL;
for ($i = 0; $i < STR_LEN; $i++) {
$randomCode .= $characters[$i];
}
echo 'Random code: ' . var_export($randomCode, true) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment