Get Website Learn Coding Tech Story

PHP Programming Examples

<?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

Learn more about user define function