1
I’m having a little problem that I’m having trouble solving. I have an array with a history of occurrences that has 5 positions, and I need to display these histories by highlighting the different items of each array. At the moment I can catch the difference between two of them, but I’m not getting the best way to receive all the differences.
$diff = array_diff($historico[3], $historico[4]);
In this case the histories of position 2,1 and 0 are missing.
The structure of the array 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
)
]
is array within array?
– Anderson Henrique
Type inside the historical array has 5 arrays?
– Anderson Henrique
Yes is a history array with an array for each update.
– Valdir Silva
I imagine you’ll have to make a recursive loop, taking each and comparing with the rest
– Marcelo
Only you put the other arrays in there, $diff = array_diff($historico[0],$historico[1],$historico[2],$historico[3],$historico[4]);
– Anderson Henrique
@Anderson Henrique that way didn’t work.
– Valdir Silva
@Marcelo I have to compare the last with the penultimate, the penultimate with the penultimate, until I arrive at the first.
– Valdir Silva
You can sort the array before it stops, https://secure.php.net/manual/en/array.sorting.php
– Marcelo