php数组到字符串转换不起作用
I am reading content from xls file and storing each value in string seperating by ,
Here is my code:
$xlsx = new SimpleXLSX('test.xlsx');
echo '<h1>$xlsx->rows()</h1>';
echo '<pre>';
print_r( $xlsx->rows() );
echo '</pre>';
$result = array();
$result = $xlsx->rows();
var_dump($result);
$result=implode(",",$result);
echo $result;
NOw:
print_r( $xlsx->rows() );
gives
Array
(
[0] => Array
(
[0] => test
[1] => karim
)
)
var_dump($result);
gives
array (size=1)
0 =>
array (size=2)
0 => string 'test' (length=4)
1 => string 'karim' (length=5)
next line
echo $result;
gives error
Notice: Array to string conversion in
what's wrong here?
我正在读取xls文件中的内容并将每个值存储在 NOw: p>
下一行 p>
, code>
$ xlsx = new SimpleXLSX('test.xlsx');
echo'&lt; h1&gt; $ xlsx-&gt; rows()&lt; / h1&gt;';
echo'&lt; pre&gt;';
print_r($ xlsx-&gt; rows());
echo'&lt; / pre&gt;';
$ result = array();
$ result = $ xlsx-&gt; rows();
var_dump($ result);
$ result = implode(“,”,$ result);
echo $ result;
代码> pre>
print_r($ xlsx-&gt; rows()); code>给出 p>
Array
(
[0] =&gt; Array
(
[0] =&gt; test
[1] =&gt; karim
)
\ n)
code> pre>
var_dump($ result); code>给出 p>
数组(大小) = 1)
0 =&gt;
array(size = 2)
0 =&gt; 字符串'test'(长度= 4)
1 =&gt; string'karim'(length = 5)
code> pre>
echo $ result; code> 给出错误 p>
注意:
code> pre>
中的数组到字符串转换
try
$result=implode(",",$result[0]);
this should implode each row into a comma separated string in a new array, called result2
$xlsx = new SimpleXLSX('test.xlsx');
echo '<h1>$xlsx->rows()</h1>';
echo '<pre>';
print_r( $xlsx->rows() );
echo '</pre>';
$result = array();
$result = $xlsx->rows();
var_dump($result);
$result=
//echo $result;
$rows = count($result);
$result2 = array();
for($i = 0; $i < $rows; $i++)
{
$result2[$i] = implode(',',$result[$i]);
}
foreach($result2 as $value)
{
echo $value.'<br/>';
}