当前位置:Gxlcms > PHP教程 > PHP数组,$a={0,1,2,3}怎样变成$a={1,2,3,4]

PHP数组,$a={0,1,2,3}怎样变成$a={1,2,3,4]

时间:2021-07-01 10:21:17 帮助过:5人阅读

PHP数组,$a = {0,1,2,3}怎样变成$a = {1,2,3,4]。就是多维数组的维,然后把维加1,输出成表格的序列号,1,2,3,4


回复讨论(解决方案)

$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
)

$arr = array(0,1,2,3);$temp = array();foreach($arr as $k=>$v){    $k++;    $temp[] = $k;}print_r($temp);


版主的更漂亮!

版主的思路漂亮,这里提供另一种思路。

输出?>

人气教程排行