admin 发表于 2023-2-16 18:54:57

PHP中array_unique()函数

<div id="article_content" class="article_content clearfix">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
                <div id="content_views" class="htmledit_views">
                  <p>$a &#61; array(&#34;a&#34;&#61;>&#34;red&#34;,&#34;b&#34;&#61;>&#34;green&#34;,&#34;c&#34;&#61;>&#34;red&#34;);</p>
<p>print_r(array_unique($a));</p>
<p></p>
<p>在PHP中使用array_unique()函数&#xff0c;用于移除数组中的重复值&#xff0c;只保留第一个值&#xff0c;其他的被移除。</p>
<h2>定义和用法</h2>
<p>array_unique() 函数用于移除数组中重复的值。如果两个或更多个数组值相同&#xff0c;只保留第一个值&#xff0c;其他的值被移除。</p>
<p><strong>注释&#xff1a;</strong>被保留的数组将保持<strong>第一个</strong>数组项的键名类型。</p>
<hr>
<h2>语法</h2>
<p>array_unique(<em>array</em>)</p>
<p></p>
<table><tbody><tr><th>参数</th><th>描述</th></tr><tr><td style="vertical-align:top;"><em>array</em></td><td style="vertical-align:top;">必需。规定数组。</td></tr><tr><td><em>sortingtype</em></td><td>可选。规定排序类型。可能的值&#xff1a;
    <ul><li>SORT_STRING - 默认。把每一项作为字符串来处理。</li><li>SORT_REGULAR - 把每一项按常规顺序排列&#xff08;Standard ASCII&#xff0c;不改变类型&#xff09;。</li><li>SORT_NUMERIC - 把每一项作为数字来处理。</li><li>SORT_LOCALE_STRING - 把每一项作为字符串来处理&#xff0c;基于当前区域设置&#xff08;可通过 <ahref="https://www.runoob.com/php/func-string-setlocale.html">setlocale()</a> 进行更改&#xff09;。</li></ul></td></tr></tbody></table>
<p></p>
<p> </p>
                </div>
      </div>
      <div id="treeSkill"></div>
页: [1]
查看完整版本: PHP中array_unique()函数