[英]Array confusion in php in loop (getting syntax error of unexpected '[') + Confusion regarding displaying CSV file using php [closed]
我是编程新手,在php中使用数组时遇到麻烦。 有人可以解释我在做什么错吗? 我收到一个错误消息:
解析错误:语法错误,在第263行的/home/jharvard/vhosts/pset7/includes/functions.php中出现意外的[[]
// declare arrays and counter to be returned
$i = 0;
$dates = array();
$prices = array();
// loops over the file and stores the values
while (($data = fgetcsv($f)) !== false)
{
$dates[$i] = data[0];
$prices[$i] = data[1];
$prices[$i] = number_format($price[$i], 2);
$i++;
}
这两行似乎缺少$符号
$dates[$i] = data[0];
$prices[$i] = data[1];
它应该是
$dates[$i] = $data[0];
$prices[$i] = $data[1];
$file = file_get_contents($csvfile);
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $file));
$cnt=count($data);
for($i=0;$i<$cnt;$i++){
@$data[$i][0] //1st column of csv //
@$data[$i][1] //2nd column
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.