I have the following output from a PHP array:
Array (
[0] => Array (
[set1] => Array (
[link] => xyz.com/def
[time] => 2016-01-03
[set2] => Array (
[link] =>
[time] => )
[set3] => Array (
[link] =>
[time] => )
)
[1] => Array (
[set1] => Array (
[link] => xyz.com/123
[time] => 2016-01-03)
[set2] => Array (
[link] =>
[time] => )
[set3] => Array (
[link] => xyz.com/123
[time] => 2016-01-03)
)
[2] => Array (
[set1] => Array (
[link] => xyz.com/abc
[time] => 2015-12-03)
[set2] => Array (
[link] => xyz.com/abc
[time] => 2016-01-03)
[set3] => Array (
[link] => xyz.com/123456
[time] => 2016-01-03)
) )
I would like to eliminate duplicate [link] regardless of the [time] - then I would like to eliminate the empty [link] values such as [0][set2], and finally have an output as follows:
[link] => xyz.com/def
[time] => 2016-01-03
[link] => xyz.com/123
[time] => 2016-01-03)
[link] => xyz.com/abc
[time] => 2015-12-03
[link] => xyz.com/123456
[time] => 2016-01-03
This is what I tried:
$categoryUrlArray= array_unique(($categoryUrlArray, SORT_REGULAR);
foreach ($categoryUrlArray as $categoryUrlLevel01) {
$categoryUrlLevel01= array_unique($categoryUrlLevel01, SORT_REGULAR);
foreach ($categoryUrlLevel01 as $categoryUrlLevel02) {
echo $categoryUrlLevel02['link'];
echo '<br/>';
echo $categoryUrlLevel02['time'];
echo '<br/><br/><br/>';
}
}
The problem with the above code is that duplicates are not being eliminated and empty values are still showing i.e. there are plenty of line breaks <br/> - that is why I know they are not being eliminated.
<br/>in it?<br/>to make it more user friendly when the result is output.