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 = array("a"=>"red","b"=>"green","c"=>"red");</p>
<p>print_r(array_unique($a));</p>
<p></p>
<p>在PHP中使用array_unique()函数,用于移除数组中的重复值,只保留第一个值,其他的被移除。</p>
<h2>定义和用法</h2>
<p>array_unique() 函数用于移除数组中重复的值。如果两个或更多个数组值相同,只保留第一个值,其他的值被移除。</p>
<p><strong>注释:</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>可选。规定排序类型。可能的值:
<ul><li>SORT_STRING - 默认。把每一项作为字符串来处理。</li><li>SORT_REGULAR - 把每一项按常规顺序排列(Standard ASCII,不改变类型)。</li><li>SORT_NUMERIC - 把每一项作为数字来处理。</li><li>SORT_LOCALE_STRING - 把每一项作为字符串来处理,基于当前区域设置(可通过 <ahref="https://www.runoob.com/php/func-string-setlocale.html">setlocale()</a> 进行更改)。</li></ul></td></tr></tbody></table>
<p></p>
<p> </p>
</div>
</div>
<div id="treeSkill"></div>
页:
[1]