我從一個PHP陣列的輸出如下:PHP - 數組中基於鍵的值和空值刪除重複值
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)
))
我想消除重複[link]
不管[time]
的 - 然後我想消除空[link]
值,如[0][set2]
,終於有一個輸出如下:
[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
這是我的嘗試:
$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/>';
}
}
與上面的代碼的問題是,重複不被淘汰,空值仍顯示出,即有大量換行符<br/>
- 這就是爲什麼我知道他們沒有被消除。
是否鏈接有'
'在裏面? – Samir
不,我不使用'
'來使結果輸出時更加用戶友好。 – xltmt