print_r数组问题
我有以下代码:
<?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
。我需要它像值数组一样输出。有什么建议吗?
I have the following code:
<?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
is outputted as string Array
. I need it outputted like array of values. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您误用了字符串连接运算符
.=
explode
为您提供了一个数组,并使用.=
将其转换为字符串Array
>。正确的方法是使用[]
运算符You are misusing string concatenation operator
.=
explode
gives you an array, and with.=
it's converted to stringArray
. The proper way is to use[]
operator您可能想尝试
var_dump
而不是print_r
。至少出于调试目的。You might want to try
var_dump
instead ofprint_r
. At least for debugging purposes.