我尝试了各种 PHP 逻辑和 PHP 内置函数来删除重复的值,但是如果使用 array_unique() in_array()
来删除数组中的重复对象,就不会出现错误,但我的所有 JQuery 和 CSS 都无法工作。
这是我在 while 循环中创建 person_row_array
的方式:
$person_row = Person::findByID($pi_claimant_row->person_id);
$person_row_array[] = $person_row;
以下是 print_r 对象:
Array
(
[0] => stdClass Object
(
[id] => 12
[flat_no] =>
[house_no] => *
[street] =>
[town] =>
[postcode] => *
[county] =>
)
[1] => stdClass Object
(
[id] => 14
[flat_no] => 2
[house_no] => 33
[street] => Street
[town] => Town
[postcode] => BB
[county] => County
)
[2] => stdClass Object
(
[id] => 14
[flat_no] => 2
[house_no] => 33
[street] => Street
[town] => Town
[postcode] => BB
[county] => County
)
[3] => stdClass Object
(
[id] => 14
[flat_no] => 2
[house_no] => 33
[street] => Street
[town] => Town
[postcode] => BB
[county] => County
)
[4] => stdClass Object
(
[id] => 15
[flat_no] => FN
[house_no] => HN
[street] => Street
[town] => Nelson
[postcode] => PC
[county] => Manchester
)
[5] => stdClass Object
(
[id] => 15
[flat_no] => FN
[house_no] => HN
[street] => Street
[town] => Nelson
[postcode] => PC
[county] => Manchester
)
[6] => stdClass Object
(
[id] => 16
[flat_no] => FN
[house_no] => house
[street] => Manchester Road
[town] => Town
[postcode] => M1 4MK
[county] => County
)
)
我想删除那些重复的数据,请帮忙,但请不要建议我使用array_unique(),我已经尝试了几个小时,但它并没有起作用。如果你能告诉我其他方法或在不存在对象时添加对象,那就太好了。
请注意,这是虚假数据,我只想删除那些具有相似id的数组。
最好的问候。
array_map('unserialize', array_unique(array_map('serialize', $person_row_array)));
- Vlad Preda