Return to Snippet

Revision: 57931
at June 15, 2012 14:13 by fmdfrank


Initial Code
//unique is built by concatenating the user input (first, last, zip)
function makeCode($unique) {
        
        //specify output string length
	$length = 5;
  
    //start with empty sting
    $string = '';
   
    
    for ($i = 0; $i < $length; $i++) {
        $string .= $unique[rand(0, strlen($unique) - 1)];

    }

    return $string;

}

Initial URL


Initial Description
For a project I needed to generate a unique code for each user the client would input manually. Each user would have four fields (first name, last name, email, zipcode). Omitting the email addresses ensures unique output because we reduce the chances of characters like; '@', '.', and strings like 'com' being reused everytime. It's simple, it's efficient and it's not overcomplicated.

Initial Title
Unique Code Generator

Initial Tags
php

Initial Language
PHP