PHP array, $a = {0,1,2,3} How to become $ A = {1,2,3,4]
PHP array, $a = {0,1,2,3} How to become $ A = {1,2,3,4]. Is the dimension of the multidimensional array, then the Vega 1, output to the table serial number, 1,2,3,4
------Solution--------------------
$a = Array (0, 1, 2, 3);
$b = Range (1, count ($a));
$c = Array_combine ($b, $a);
Print_r ($c);
Array
(
[1] = 0
[2] = 1
[3] = 2
[4] = 3
)
------Solution--------------------
$arr = Array (0,1,2,3);
$temp = Array ();
foreach ($arr as $k = = $v) {
$k + +;
$temp [] = $k;
}
Print_r ($temp);
The moderator's more beautiful!
------Solution--------------------
The moderator's idea is beautiful, here is another way of thinking.
$a = array (0,1,2,3);
Array_unshift ($a, 0); Inserts a new element at the beginning of the array, making the key self-increment by 1
unset ($a [0]); Delete the new element at the beginning, but the key remains unchanged
Print_r ($a); Output
?>