What I have is an array that sends the following:
> Array
(
[0] => CTS-005X000S101
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
[4] => CTS-005X000S101
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
[4] => CTS-005X000S101
[5] => CTS-015X000S101
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
[4] => CTS-005X000S101
[5] => CTS-015X000S101
[6] => 9327279-0
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
[4] => CTS-005X000S101
[5] => CTS-015X000S101
[6] => 9327279-0
[7] => 9327279-0
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
[4] => CTS-005X000S101
[5] => CTS-015X000S101
[6] => 9327279-0
[7] => 9327279-0
[8] => 9323350-0
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
[4] => CTS-005X000S101
[5] => CTS-015X000S101
[6] => 9327279-0
[7] => 9327279-0
[8] => 9323350-0
[9] => 9323350-0
)
Array
(
[0] => CTS-005X000S101
[1] => CTS-005X000S101
[2] => 9327279-0
[3] => 9311321-0
[4] => CTS-005X000S101
[5] => CTS-015X000S101
[6] => 9327279-0
[7] => 9327279-0
[8] => 9323350-0
[9] => 9323350-0
[10] => 9323409-0
)
And what I have to do is that every time an element of the next array is "repeated" it must be eliminated.
I don't have a pre defined code I only have that output. If I had to create a code it would be something like this.
foreach ($listSkus->list as $key => $sku1) {
foreach($listSkus->list as $key => $sku2){
$array1[] = $sku1->sku;
$array2[] = $sku2->sku;
if($array1 == $array2){
unset($array1);
unset($array2);
}else{
print_r("<pre>");
print_r($array1);
print_r("</pre>");
}
}
}
I really need ideas like going row by row and comparing them... Maybe with a for or while if they have references I would appreciate it.
The idea is that you do the cheapest option, without nesting things. So, instead of nesting and having an O(n^2) algorithm, build one
$arrayDefinitivo
and add the elements of each input array there, validating beforehand that they are not there.So, for each element of each input array (which you only have to go through once), you go looking if there is an element with that value to see if you add it or not.
The output will be that Definitive array...
You can use the PHP-DS extension if you have PHP >= 7 https://www.php.net/manual/en/book.ds.php