Incremental number in PHP [closed]

0

I have a system that issues an XML. It was done in PHP. In XML it has a tag which is a random number, but has to be incremental.

That is, in tag it has the number 1000. The next tag must have the number 1001.

This is easy to do in PHP. I left a fixed variable and each time it clicks to emit, it increases. But all XML is coming with equal numbers, as it is incrementing from a fixed variable.

How to make each XML have its incremental number?

    
asked by anonymous 06.01.2017 / 21:26

1 answer

0

Good morning, I suggest you use a large number in the NF-e Batch style, it's a 15-digit number, so you generate it from the microtime() function, for example:

echo substr(str_replace(',', '', number_format(microtime(true)*1000000, 0)), 0, 15);

The credits are from the NFePHP project: link

Note: In my understanding, either it is random or it is sequential, so either use a random generation as mt_rand() ~ or ~ start at 1 or 0 and incremental, I see as distinct concepts. If "it has to be incremental" as you wrote, then it is not random.

    
07.01.2017 / 12:43