【发布时间】:2019-01-07 12:47:52
【问题描述】:
Array
(
[0] => Array
(
[user_id] => 78
[post_id] => 3
[post_user_added_id] => 2
)
[1] => Array
(
[user_id] => 76
[post_id] => 8
[post_user_added_id] => 16
)
[2] => Array
(
[user_id] => 78
[post_id] => 9
[post_user_added_id] => 12
)
[3] => Array
(
[user_id] => 76
[post_id] => 9
[post_user_added_id] => 15
)
[4] => Array
(
[user_id] => 77
[post_id] => 9
[post_user_added_id] => 15
)
)
这里的想法是当有重复的user_id时,它只会显示一个?这是预期的结果:
Array
(
[2] => Array
(
[user_id] => 78
[post_id] => 9
[post_user_added_id] => 12
)
[3] => Array
(
[user_id] => 76
[post_id] => 9
[post_user_added_id] => 15
)
[4] => Array
(
[user_id] => 77
[post_id] => 9
[post_user_added_id] => 15
)
)
之所以显示[2]键而不是[0]键或[1]键而不是[3]是因为我想获取重复键的底部键。这有点难以解释,但我希望你能理解我所期望的场景或输出。
您的帮助将不胜感激!谢谢! :)
【问题讨论】:
-
到目前为止你尝试过什么? - 请发布您的代码,并明确说明您遇到了障碍。
-
我没有尝试任何东西,因为我真的不知道执行预期输出的逻辑。
-
这个网站是为程序员准备的,所以请在此处查看常见问题解答。
-
您是否考虑过将数组移入数据库?
-
我是一名程序员,这就是我想出 PHP 数组值的原因。我只是问如何删除数组上的重复值。
标签: php multidimensional-array