0

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?

1
  • Are you sure, it's not the implode() function returning that notice? :) Commented Jul 3, 2014 at 6:55

2 Answers 2

2

try

$result=implode(",",$result[0]);
Sign up to request clarification or add additional context in comments.

Comments

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/>';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.