欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

php去除數(shù)組重復(fù)數(shù)據(jù),php數(shù)組去重函數(shù)

如何正確實現(xiàn)PHP刪除數(shù)組重復(fù)元素

array_unique

成都創(chuàng)新互聯(lián)是專業(yè)的隆堯網(wǎng)站建設(shè)公司,隆堯接單;提供網(wǎng)站設(shè)計、網(wǎng)站制作,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行隆堯網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!

(PHP 4 = 4.0.1, PHP 5, PHP 7)

array_unique — 移除數(shù)組中重復(fù)的值

說明

array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )

array_unique() 接受 array 作為輸入并返回沒有重復(fù)值的新數(shù)組。

注意鍵名保留不變。array_unique() 先將值作為字符串排序,然后對每個值只保留第一個遇到的鍵名,接著忽略所有后面的鍵名。這并不意味著在未排序的 array 中同一個值的第一個出現(xiàn)的鍵名會被保留。

Note: 當(dāng)且僅當(dāng) (string) $elem1 === (string) $elem2 時兩個單元被認(rèn)為相同。就是說,當(dāng)字符串的表達(dá)一樣時。 第一個單元將被保留。

參數(shù)

array

輸入的數(shù)組。

sort_flags

The optional second parameter sort_flags may be used to modify the sorting behavior using these values:

Sorting type flags:

SORT_REGULAR - compare items normally (don't change types)

SORT_NUMERIC - compare items numerically

SORT_STRING - compare items as strings

SORT_LOCALE_STRING - compare items as strings, based on the current locale.

返回值

Returns the filtered array.

更新日志

版本

說明

5.2.10 Changed the default value of sort_flags back to SORT_STRING.

5.2.9 Added the optional sort_flags defaulting to SORT_REGULAR. Prior to 5.2.9, this function used to sort the array with SORT_STRING internally.

范例

Example #1 array_unique() 例子

?php

$input = array("a" = "green", "red", "b" = "green", "blue", "red");

$result = array_unique($input);

print_r($result);

?

以上例程會輸出:

Array

(

[a] = green

[0] = red

[1] = blue

)

Example #2 array_unique() 和類型

?php

$input = array(4, "4", "3", 4, 3, "3");

$result = array_unique($input);

var_dump($result);

?

以上例程會輸出:

array(2) {

[0] = int(4)

[2] = string(1) "3"

}

參見

array_count_values() - 統(tǒng)計數(shù)組中所有的值出現(xiàn)的次數(shù)

注釋

Note: Note that array_unique() is not intended to work on multi dimensional arrays.

php 去掉完全相同的重復(fù)數(shù)組

一、這個沒有被合并,只是取的后面這個鍵名的值,

二、$input=array("11"="aaaa","22"="bbbb","33"="cccc","11"="aaada","44"="cccc1","55"="cccc");

$result

=

array_unique

($input);

print_r($result);

輸出的結(jié)果:Array

(

[11]

=

aaada

[22]

=

bbbb

[33]

=

cccc

[44]

=

cccc1

)

鍵名33

55

的值完全一樣的時候,后者會被干掉

如果你要的是鍵名和值完全一致的時候才刪除一個的話,似乎不能,因為鍵名是不允許重復(fù)的

聽你的情況似乎數(shù)據(jù)量很大,建議你使用

array_flip()函數(shù)

【php中,刪除數(shù)組中重復(fù)元素有一個可用的函數(shù),那就是array_unique(),

但是它并不是一個最高效的方法,使用array_flip()函數(shù)將比array_uniqure()在速度上高出五倍左右。】

例子:$input=array("11"="aaaa","22"="bbbb","33"="cccc","11"="aaada","44"="cccc1","55"="cccc");

$arr1

=

array_flip(array_flip($input));

print_r($arr1);

輸出的結(jié)果:Array

(

[11]

=

aaada

[22]

=

bbbb

[55]

=

cccc

[44]

=

cccc1

)

php數(shù)組怎么去除重復(fù)的數(shù)組值

array_unique() 函數(shù)定義和用法

移除數(shù)組中的重復(fù)的值,并返回結(jié)果數(shù)組。

當(dāng)幾個數(shù)組元素的值相等時,只保留第一個元素,其他的元素被刪除。

返回的數(shù)組中鍵名不變。

例子

?php

$a=array("a"="Cat","b"="Dog","c"="Cat");

print_r(array_unique($a));

?

輸出:Array ( [a] = Cat [b] = Dog )

新聞名稱:php去除數(shù)組重復(fù)數(shù)據(jù),php數(shù)組去重函數(shù)
轉(zhuǎn)載注明:http://chinadenli.net/article22/dsgcojc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計響應(yīng)式網(wǎng)站網(wǎng)站維護(hù)商城網(wǎng)站網(wǎng)頁設(shè)計公司建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)