public static function generateRecoveryCodes($count = 1, $length = 9)
    {
        $count = intval($count);
        $length = intval($length);
        $codes = [];

        do {
            // Generate codes
            $code = '';
            for ($i = 1; $i <= $length; $i++) {
                $code .= random_int(0, 9);
            }

            // To make sure no duplicates get in
            if (!in_array($code, $codes)) {
                $codes[] = $code;
            }
        } while (count($codes) < $count);

        return $codes;
    }
public static function generateRecoveryCodes($count = 1, $length = 9)
    {
        $count = intval($count);
        $length = intval($length);
        $codes = [];

        do {
            // Generate codes
            $code = '';
            for ($i = 1; $i <= $length; $i++) {
                $code .= random_int(0, 9);
            }

            // To make sure no duplicates get in
            if (!in_array($code, $codes)) {
                $codes[] = $code;
            }
        } while (count($codes) < $count);

        return $codes;
    }
public static function generateRecoveryCodes ( $ count = 1 , $ length = 9 ) { $ count = intval ( $ count ) ; $ length = intval ( $ length ) ; $ codes = [ ] ; do { // Generate codes $ code = '' ; for ( $ i = 1 ; $ i <= $ length ; $ i ++ ) { $ code .= random_int ( 0 , 9 ) ; } // To make sure no duplicates get in if ( ! in_array ( $ code , $ codes ) ) { $ codes [ ] = $ code ; } } while ( count ( $ codes ) < $ count ) ; return $ codes ; }
Create recovery codes

A pure helper function to make your life easier. Generates a list of codes, guaranteed to be unique in the set

@param integer $count How many codes to return
@param integer $length How long each code should be

@return array Array of codes
Create recovery codes