Alan Williams
Alan Williams

Reputation: 35

list values into array

I'm fairly new to php, so please excuse my ignorance here... :P

I have the following code:

<?php
$fh = fopen("../filename.csv", "r");
while (list($siteid, $sitename, $scheduled, $arecords, $crons, $sslintf, $customip, $psccjobs, $odbc, $sitesize, $dbsize, $nfssize, $fasize, $siteclass, $dbexport, $chatver, $socintf, $sitemode, $mailboxes, $mailfiles, $oesmtp) = fgetcsv($fh, 1024, ";")) {
    echo "<p>$siteid, $sitename, $scheduled, $arecords, $crons, $sslintf, $customip, $psccjobs, $odbc, $sitesize, $dbsize, $nfssize, $fasize, $siteclass, $dbexport, $chatver, $socintf, $sitemode, $mailboxes, $mailfiles, $oesmtp</p>";
}
?>

I want to add each row of variables into an array...

Any Suggestions would be helpful, even if there is a better approach.

Upvotes: 0

Views: 63

Answers (1)

Marc B
Marc B

Reputation: 360772

gah.... why not simply

while($row = fgetcsv($fh)) {
    echo "<p>", implode(', ', $row), "</p>";
}

If you want to store each row in an array, then

$data = array();
while($row = fgetcsv($fh)) {
    echo "<p>", implode(', ', $row), "</p>";
    $data[] = $row;
}

Upvotes: 3

Related Questions