【发布时间】:2019-07-14 19:55:52
【问题描述】:
大家好,
我的任务是更改数组中的索引。 这是我的代码:
$file = Storage::get('upload/test.txt');
$lines = explode('\n', $file);
$array = array_map(function($line) {
return explode(',', $line);
}, $lines);
print_r($array);
输出是:
数组 ( [0] => 数组 ( [0] => 约翰 [1] => 男性 [2] => 20 [3] => 200 [4] => 174 )
[1] => Array
(
[0] => joe
[1] => male
[2] => 24
[3] => 157
[4] => 166
)
[2] => Array
(
[0] => bea
[1] => female
[2] => 18
[3] => 153
[4] => 160
)
[3] => Array
(
[0] => edd
[1] => male
[2] => 30
[3] => 180
[4] => 180
)
)
我需要做的是:
数组 ( [0] => 数组 ( [名称] => 约翰 [性别] => 男性 [年龄] => 20 [身高] => 200 [重量] => 174 )
[1] => Array
(
[name] => joe
[sex] => male
[age] => 24
[height] => 157
[weight] => 166
)
[2] => Array
(
[name] => bea
[sex] => female
[age] => 18
[height] => 153
[weight] => 160
)
[3] => Array
(
[name] => edd
[sex] => male
[age] => 30
[height] => 180
[weight] => 180
)
)
提前致谢! :)
【问题讨论】:
标签: php arrays indexing foreach