Skip to content

Instantly share code, notes, and snippets.

@ArbahudRioDaroyni
Created January 31, 2020 13:51
Show Gist options
  • Save ArbahudRioDaroyni/f92ce7d095e0c824fcc0eef060c9d156 to your computer and use it in GitHub Desktop.
Save ArbahudRioDaroyni/f92ce7d095e0c824fcc0eef060c9d156 to your computer and use it in GitHub Desktop.
Generate String and Number
<?php
function generateRandomString($length = 10) {
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function generateRandomNumber($length = 10) {
$characters = '0123456789';
$charactersLength = strlen($characters);
$randomNumber = '';
for ($i = 0; $i < $length; $i++) {
$randomNumber .= $characters[rand(0, $charactersLength - 1)];
}
return $randomNumber;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment