Good day everyone,
I was tasked to change index in arrays. here is my code:
$file = Storage::get('upload/test.txt');
$lines = explode('\n', $file);
$array = array_map(function($line) {
return explode(',', $line);
}, $lines);
print_r($array);
output is:
Array ( [0] => Array ( [0] => john [1] => male [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
)
)
what i need to happen is:
Array ( [0] => Array ( [name] => john [sex] => male [age] => 20 [height] => 200 [weight] => 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
)
)
thanks in advance! :)