Function

<?php
	/* User define function */
	function random_code($digits) {
		
		/* Characters to generate random code */
		$possible = '1234563789ABDEFGHJKLMNopqrtvwxy';
		$code = '';
		$i = 0;
		
		/* Loop the process upto user define length of the code */
		while ($i < $digits) { 
			$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
			$i++;
		}
		
		/* Return random value */
		return $code;
	}
	
	/* Call user define function with parameter */
	echo "Your random code is: ".random_code(8);
?>



/* Output */
Your random code is: wExHyJ93

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!