Terminal number script in php [closed]

0

I have tried to create a script that will help me to carry the code of each person and the variant is that it is not an auto increment of it, that is, Axis: The number terminal is filled in the following way 0 0 0 which the increase will be seen in third number 0 0 1 reached a hundred this third number is reset 0 0 1 ... 0 0 100 and will return to zero and the second number will be incremented 0 1 0 so on. As I said before I tried to develop something similar but I ended up in failure

    
asked by Josbert Hernandez 24.02.2017 в 01:48
source

2 answers

1

I think with something like this you should be worth:

<?php

$numbers = [0,0,0];

for ($numbers[2]=0; $numbers[2] <= 101; $numbers[2]++)
{ 

    if( $numbers[2] == 101 ) 
    {

        $numbers[2] = 0;

        $numbers[1]++;

        if( $numbers[1] == 101 ) 
        {

            $numbers[1] = 0;

            $numbers[0]++;

            if( $numbers[0] == 100 ) 
            {

                $numbers[2] = 0;

                $numbers[1] = 0;

                break;

            }

        }

    }

    echo $numbers[0] . ' ' . $numbers[1] . ' ' . $numbers[2] . '<br>';

}

?>
    
answered by 24.02.2017 в 02:17
-1

What you want to do you already have done. You are limited to showing different digits of a number.

0 00 00 -> 000000
0 01 00 -> 000100
1 99 05 -> 019905

You can use an integer and increase it tancally.

When you need to access its specific parts, it is where you have to make a small operation:

$numero = 110;
$cadena = '00000' . (string)$numero;
$numeros = [
  0 => substr( $cadena, -6, 2 ),
  1 => substr( $cadena, -4, 2 ),
  2 => substr( $cadena, -2, 2 ),
];

echo "{$numeros[0]}, {$numeros[1]}, {$numeros[2]}\n";
    
answered by 24.02.2017 в 07:32