我有以下代码:
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("coockie");
$filename ="excelreport.xls";
$contents = "date \t ip \t visits \t \n";
$result=mysql_query("select * from test");
$mydate='';
$myip='';
$visits='';
while($data=mysql_fetch_assoc($result))
{
$mydate.=explode(",", $data['date']);
$myip.=explode(",", $data['ip']);
$visits.=$data['visits'];
}
print_r($mydate);
//header('Content-type: application/ms-excel');
//header('Content-Disposition: attachment; filename='.$filename);
//echo $contents;
?>
$mydate
以字符串Array
输出。我需要输出像数组的值。有什么建议吗?
答案 0 :(得分:2)
您滥用字符串连接运算符.=
$mydate.=explode(",", $data['date']);
explode
为您提供了一个数组,并使用.=
将其转换为字符串Array
。正确的方法是使用[]
运算符
$mydate=array();
$myip=array();
$visits='';
while($data=mysql_fetch_assoc($result))
{
$mydate[]=explode(",", $data['date']);
$myip[]=explode(",", $data['ip']);
$visits.=$data['visits'];
}
print_r($mydate);
答案 1 :(得分:1)
您可能想要var_dump
而不是print_r
。至少用于调试目的。
var_dump($mydate);