Home  >  Article  >  php教程  >  php数组的小函数之想

php数组的小函数之想

WBOY
WBOYOriginal
2016-06-13 10:55:511045browse

最近项目需要对数组有这么一个要求,数组本身的内容可能会不断改变,如果知道数组的某个键名,如何获取下一个键名?

刚开始的时候以为会不好写,就不断书上找数组的相关函数,又去网上搜索,发现都没有。

于是自己动手写写,没想到如此简单就写好了。

[html]  

/*  

  * 求数组当前键名的下一个键名  

  * $array  数组  

  * $keys   当前的键名  

  * 返回下一个键名  

  */  

  function next_array($array,$keys){  

    $n=0;  

    foreach($array as $key =>$value){  

        if($n==1)  

        return $key;  

        if($key == $keys)  

        $n++;  

    }  

}  

      发现很多时候,还是得靠自己。

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
Previous article:PHP安装新的扩展库Next article:CI中如何去掉index.php