1
print_r($ jobtypes)給我一個數組。數組包含重複的元素。我想刪除重複項。這是一個陣列刪除多維數組中的重複項
Array
(
[0] => stdClass Object
(
[term_id] => 40
[name] => Babysitting
[slug] => babysitting
[term_group] => 0
[term_taxonomy_id] => 40
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 3
)
[1] => stdClass Object
(
[term_id] => 43
[name] => Lawn Mowing
[slug] => lawn-mowing
[term_group] => 0
[term_taxonomy_id] => 43
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 3
)
[2] => stdClass Object
(
[term_id] => 39
[name] => Leaf Raking
[slug] => leaf-raking
[term_group] => 0
[term_taxonomy_id] => 39
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 2
)
[3] => stdClass Object
(
[term_id] => 41
[name] => Pet Sitting
[slug] => pet-sitting
[term_group] => 0
[term_taxonomy_id] => 41
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 3
)
[4] => stdClass Object
(
[term_id] => 42
[name] => Plant Watering
[slug] => plant-watering
[term_group] => 0
[term_taxonomy_id] => 42
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 2
)
[5] => stdClass Object
(
[term_id] => 44
[name] => Snow Shoveling
[slug] => snow-shoveling
[term_group] => 0
[term_taxonomy_id] => 44
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 5
)
[6] => stdClass Object
(
[term_id] => 40
[name] => Babysitting
[slug] => babysitting
[term_group] => 0
[term_taxonomy_id] => 40
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 3
[filter] => raw
)
)
如何刪除重複項。我這種情況下
[name] => Babysitting
[slug] => babysitting
[term_group] => 0
[term_taxonomy_id] => 40
[taxonomy] => job_listing_type
[description] =>
[parent] => 0
[count] => 3
[filter] => raw
是兩倍。我用
$jobtypes= array_map("unserialize", array_unique(array_map("serialize", $jobtypes)));
但不工作。謝謝
是什麼語言?請添加標籤。 – zishe
其php語言 – Riz
數據從哪裏來?如果它來自數據庫,則應該編寫查詢,以便重複結果不包含在結果中。另外,你在問之前是否(使用搜索)(https://stackoverflow.com/search?q=%5Bphp%5D+array+remove+duplicates)?有很多[問題](https://stackoverflow.com/questions/3579749/removing-duplicates-from-an-array)基本上要求同樣的事情。 –