Home > Backend Development > PHP Tutorial > Thoughts on small functions of php array_PHP tutorial

Thoughts on small functions of php array_PHP tutorial

WBOY
Release: 2016-07-14 10:09:31
Original
958 people have browsed it

Recent projects have such a requirement for arrays. The contents of the array itself may keep changing. If you know a certain key name of the array, how to get the next key name?

At first I thought it would be difficult to write, so I kept looking for array-related functions in books and searching online, but found none.
So I started writing it myself, and I didn’t expect it to be so easy.
[html]
/*
* Find the next key name of the current key name in the array
* $array array
* $keys Current key name
* Return the next key name
*/
function next_array($array,$keys){
$n=0;
foreach($array as $key =>$value){
if($n==1)
return $key;
if($key == $keys)
$n++;
}
}
I found that many times, you still have to rely on yourself.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477630.htmlTechArticleRecent projects need to have such a requirement for arrays. The content of the array itself may continue to change. If you know some of the array A key name, how to get the next key name? At the beginning...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template