I have the following php code that displays csv data on the browser:
$file1 = file('SpreadsheetA.csv',FILE_IGNORE_NEW_LINES);
foreach($file1 as $val)
{
echo $val;
}
the above outputs all the data in the csv file as a string:
Matter Number,Amount,Currency,Company Code100,2000,USD,310101,23000,EUR,110102,120,GBP,120103,10000,USD,310
if i want to capture the above as an array, this is what i do:
foreach($file1 as $val)
{
var_dump(array($val));
}
and this is the output:
array(1) {
[0]=>
string(42) "Matter Number,Amount,Currency,Company Code"
}
array(1) {
[0]=>
string(16) "100,2000,USD,310"
}
array(1) {
[0]=>
string(17) "101,23000,EUR,110"
}
array(1) {
[0]=>
string(15) "102,120,GBP,120"
}
array(1) {
[0]=>
string(17) "103,10000,USD,310"
}
as shown, each string is captured as an array..my wish is to capture all strings under a single array as follows:
array(5) {
[0]=>
string(42) "Matter Number,Amount,Currency,Company Code"
[1]=>
string(16) "100,2000,USD,310"
[2]=>
string(17) "101,23000,EUR,110"
[3]=>
string(15) "102,120,GBP,120"
[4]=>
string(17) "103,10000,USD,310"
}
how would i accomplish the above(inside the foreach loop)??