Compare two arrays of numbers

0

I'm having a hard time comparing PHP between two arrays .

I have Array HORA_INICIAL and HORA_FINAL what I need to do:

In the Initial Time array compare the Hora Inicial < Hora Final and display the End Time index to be greater.

    
asked by anonymous 03.10.2017 / 21:41

1 answer

0

If I understand you, you have two arrays with the same amount of elements, which should be compared based on your index, to see if the first has a value greater than the second.

Let's exemplify:

// Array com as horas iniciais
$arrayHoraInicial = array(
    '09:32:00',
    '11:20:10',
    '13:06:55',
    '19:10:10',
);

// Array com as horas finais
$arrayHoraFinal = array(
    '09:50:00',
    '12:10:00',
    '12:25:15',
    '21:11:08',
);

// Captura quantos elementos existem no array.    
$quantidade = count($arrayHoraInicial); 

// Realiza um loop for para percorrer os arrays.    
for ($i = 0; $i < $quantidade; $i++) {
    // Compara horas string
    if($arrayHoraFinal[$i] < $arrayHoraInicial[$i]) {
        echo "O índice $i apresenta um valor final maior que o inicial";
    }
}

In the example above the printed result will be:

Index 2 presents a final value greater than the initial

    
03.10.2017 / 22:27