I have data from a csv file that I organized into a multidimensional array using the following method:
$handle = fopen("bankdata.csv", "r");
while(($data = fgetcsv($handle, 0 ,",")) !==FALSE) {
$transactions[] = $data;
}
The array now looks something like this:
Array
(
[0] => Array
(
[0] => 2000
[1] => paycheck
[2] => credit
)
[1] => Array
(
[0] => 75
[1] => grocery
[2] => debit
)
[2] => Array
(
[0] => 45
[1] => gas
[2] => debit
)
[3] => Array
(
[0] => 900
[1] => investments
[2] => credit
)
[4] => Array
(
[0] => 1500
[1] => bonus
[2] => credit
)
Now I would like to name the keys in each nested array. I thought I would create a new multidimensional array with an equal amount of nested arrays, their values being the intended name of the keys I would like to add to the original array, then do 'array_combine':
$names = array('amount','source','type');
$run = 1;
while($run < 6){
$run = $run +1;
$names2[] = $names;
}
$combine = array_combine($names2, $transactions);