Home > Backend Development > PHP Tutorial > PHP method to restore the key of an array to a numerical sequence, array key_PHP tutorial

PHP method to restore the key of an array to a numerical sequence, array key_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:55:31
Original
950 people have browsed it

How PHP restores the key of an array to a sequence of numbers, array key

The example in this article describes how PHP restores the key of an array to a sequence of numbers. Share it with everyone for your reference. The specific analysis is as follows:

Here, PHP is implemented to restore the key value of the array into a sequence of numbers similar to 0,1,2,3,4,5...

function restore_array($arr){
 if (!is_array($arr)){ return $arr; }
 $c = 0; $new = array();
 while (list($key, $value) = each($arr)){
  if (is_array($value)){
   $new[$c] = restore_array($value);
  }
  else { $new[$c] = $value; }
  $c++;
 }
 return $new;
}
Copy after login

Demo example:
Copy code The code is as follows: restore_array(array('a' => 1, 'b' => 2)); --> returns array(0 => 1, 1 => 2)

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/991805.htmlTechArticlephp method to restore the key of an array to a sequence of numbers, array key This article describes how to restore the key of an array to a number in php sequence method. Share it with everyone for your reference. The specific analysis is as follows:...
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template