search
Homephp教程php手册自己写的一个数组操作函数

上午刚需要的一个功能,在手册上找到了一个函数,但是不是我想要的结果
最后改了改实现了,拿来分享下。
//函数功能:消除数组重复项,并且让键值重新从0开始排列<br>         function array_unrepeat($input){<br>             $input = array_unique($input);<br>             $keys = array();<br>             for($i=0;$i<count></count>                 $keys[$i] = $i;<br>             }<br>             return  array_combine($keys, $input);<br>         }<br> //用法示例:        <br> //$input  = array(0,0,1,1,2,2,3,3,4,4,7,7);<br> //var_dump(array_unrepeat($input));<br> //输出<br> //array (size=6)<br>   // 0 => int 0<br>   // 1 => int 1<br>   // 2 => int 2<br>   // 3 => int 3<br>   // 4 => int 4<br>   // 5 => int 7------------------------------
Update:
从广大网友那里得到的更简单的方法:
$result = array_values(array_unique ($input));
$result = array_keys(array_flip($input));

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor