___ ___ erkimt Compare arrays and highlight changes ______ qstntxt ___

I have a problem that I can not solve. I have an array with a history of occurrences that has 5 positions, and I need to make the display of these histories highlighting the different items of each array. At the moment I can get the difference between two of them, but I can not figure out the best way to receive all the differences.

%pre%

In this case the history of positions 2.1 and 0 is missing.

The array structure I have is this:

%pre%

]

    
______ azszpr305471 ___

I do not know why, but if you want to take it back from doing so

%pre%

You can also have another way without needing the less

%pre%     
___

1

I have a problem that I can not solve. I have an array with a history of occurrences that has 5 positions, and I need to make the display of these histories highlighting the different items of each array. At the moment I can get the difference between two of them, but I can not figure out the best way to receive all the differences.

$diff = array_diff($historico[3], $historico[4]);

In this case the history of positions 2.1 and 0 is missing.

The array structure I have is this:

[
[0] => Array
    (         
        [0] => 07/06/2018 15:49:00
        [1] => Questionamento :  teste questionamento  
    )
[1] => Array
    (
        [0] => 07/06/2018 15:50:00
        [1] => Questionamento :  teste questionamento 2
    )
 [2] => Array
    (
        [0] => 07/06/2018 15:51:00
        [1] => Questionamento :  teste questionamento 3
    )
 [3] => Array
    (
        [0] => 07/06/2018 15:52:00
        [1] => Questionamento :  teste questionamento 4
    )
  [4] => Array
    (
        [0] => 07/06/2018 15:53:00
        [1] => Questionamento :  teste questionamento 5
    )

]

    
asked by anonymous 08.06.2018 / 15:07

1 answer

1

I do not know why, but if you want to take it back from doing so

#array para pegar as diferenças
$diferencas = array();
#for pegando o tamanho do array e diminuindo, o motivo do menos 1 é que o array inicia de 0 então mesmo tendo 4 registros seriam de 0 a 3 no caso 3, teria que diminuir 1
for($i = sizeof($historico) - 1; $i > 0; $i--):
    #adiciona a comparacao de array da posicao atual com uma anterior
    array_push($diferencas,array_diff($historico[$i],$historico[$i - 1]));
endfor;
#printa as diferencas
print_r($diferencas);

You can also have another way without needing the less

 #array para pegar as diferenças
$diferencas = array();
#Reverte as posicoes dos arrays de tras pra frente, ultimas chaves viram primeiras
krsort($historico);
for($i=0; $i < sizeof($historico) - 1; $i++):
array_push($diferencas,array_diff($historico[$i],$historico[$i + 1]));  
endfor;
print_r($diferencas);
    
08.06.2018 / 16:03