php一维数组转成二维数组

(1)数值数组从一维转成二维

$c = [0,1,2,3,4];
$d = array();
foreach($c as $key => $value){
    $d[] = [$value];
}
var_dump($d);

打印如下图所示


image.png

(2)索引数组从一维转成二维

$a = [
    'time1'=>'123',
    'time2'=>'456'
];
$b = array();
foreach ($a as $key => $value){
    $b[] = [$key => $value];
}
var_dump($b);

打印如下图所示


image.png

你可能感兴趣的:(php一维数组转成二维数组)