Coding a permutation functions : ID into a 6 chars string in PHP

Cancelado Publicado hace 6 años Pagado a la entrega
Cancelado Pagado a la entrega

For a project of mine coded in PHP with Laravel, I'm having a customer table in my database. This table has an ID with auto-increment.

I'm trying to code a function to transform that ID into a string following specific rules :

- The size of the string is 6 caracters maximum

- Caracters in the string are part of [0-9a-v]

- This is the : The "Extended Hex" Base 32 Alphabet

- No maj in the letters

- the letters will be incremented from left

- the numbers will be incremented from right

When I'm inserting a new customer into the database, I should call a function that will transform the ID just generated into a specific string. Here is an example with on the left, the string it should be transformed into, and on the right the ID in the database :

000001 = 0 000 001

999999 = 0 999 999

a00000 = 1 000 000

a00001 = 1 000 001

a10000 = 1 010 000

a99999 = 1 099 999

b00000 = 1 100 000

b99999 = 1 199 999

c00000 = 1 200 000

d00000 = 1 300 000

e00000 = 1 400 000

f00000 = 1 500 000

g00000 = 1 600 000

h00000 = 1 700 000

i00000 = 1 800 000

j00000 = 1 900 000

k00000 = 2 000 000

v00000 = 3 200 000

v99999 = 3 999 999

aa0000 = 4 000 000

aa0001 = 4 000 001

ab0000 = 4 010 000

ac0000 = 4 020 000

ad0000 = 4 030 000

ae0000 = 4 040 000

af0000 = 4 050 000

ag0000 = 4 060 000

ah0000 = 4 070 000

ai0000 = 4 080 000

aj0000 = 4 090 000

ak0000 = 4 100 000

av0000 = 4 200 000

av9999 = 4 209 999

ba0000 = 4 210 000

...

vvvvvv = Number maximum of possible permutations so : 652 458 240

<!> : Maybe I did some mistakes in my calculations.

I need someone to code my that function because I'm totally blocking.

The function should be provided like this :

/**

* Generate identifier associated to the ID of the customer

*

* @param <int> $customerID The customer id

*

* @return <string> $identifier The identifier associated to the customer

*/

function generateCustomerIdentifier($customerID)

Examples :

generateCustomerIdentifier(1) should return : 000001

generateCustomerIdentifier(999999) should return : 999999

generateCustomerIdentifier(1000000) should return : a00000

generateCustomerIdentifier(652458240) should return : vvvvvv

I need this ASAP.

Algoritmos Matemáticas MySQL PHP

Nº del proyecto: #14657395

Sobre el proyecto

2 propuestas Proyecto remoto Activo hace 6 años