How PHP restores the key of an array to a sequence of numbers
This article describes an example of 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...
?
1
2
3
4
5
6
7
8
9
10
11
12
|
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;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
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;
}
|
Demonstration example:
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.
http://www.bkjia.com/PHPjc/991650.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/991650.htmlTechArticleHow to restore the key of an array to a sequence of numbers in php. This article explains how to restore the key of an array to a sequence of numbers in php. . Share it with everyone for your reference. The specific analysis is as follows: Here is the implementation...