如何在PHP中从数组中删除重复值

如何在PHP中从数组中删除重复值

如何从PHP数组中删除重复值?



慕田峪4524236
浏览 1114回答 3
3回答

肥皂起泡泡

使用数组_UNIQUE().例子:$array = array(1, 2, 2, 3);$array = array_unique($array); // Array is now (1, 2, 3)

慕沐林林

//Find duplicates $arr = array(      'unique',      'duplicate',      'distinct',      'justone',      'three3',      'duplicate',      'three3',      'three3',      'onlyone' );$unique = array_unique($arr); $dupes = array_diff_key( $arr, $unique );      // array( 5=>'duplicate', 6=>'three3' 7=>'three3' )// count duplicatesarray_count_values($dupes); // array( 'duplicate'=>1, 'three3'=>2 )

qq_笑_17

使用array_values(array_unique($array));array_unique*用于唯一数组array_values*重新编制索引
打开App,查看更多内容
随时随地看视频慕课网APP