Thu May 28 2020

Function

PHP Scripting1161 views

File Name: php-function.php

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

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