且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 从多维数组中删除重复值

更新时间:2023-02-23 09:51:56

用户对 array_unique 的评论页面确实对此有所了解.您很可能会在这些评论中找到一些隐藏的宝石 - 这是一个非常方便的文档.

The user comments on the array_unique page do shed some light on this. You will most likely find some hidden gems in those comments - its a very handy documentation.

通过快速浏览器显示以下内容以从多维数组中删除重复项:

Just a quick browser through revealed the following to remove duplicates from a multi dimensional array:

<?php
function super_unique($array)
{
  $result = array_map("unserialize", array_unique(array_map("serialize", $array)));

  foreach ($result as $key => $value)
  {
    if ( is_array($value) )
    {
      $result[$key] = super_unique($value);
    }
  }

  return $result;
}
?>