将值列入数组

时间:2013-03-04 18:27:53

标签: php arrays list csv

我对php很新,所以请原谅我的无知......:P

我有以下代码:

<?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>";
}
?>

我想将每行变量添加到数组中......

即使有更好的方法,任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:3)

gah ....为什么不简单

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

如果要将每一行存储在一个数组中,那么

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