Reputation: 12512
I have a page where I output some data (page1.php). Also I have another page (page2.php) where I need to pass the values as well.
// page1.php
$myVals = '""';
foreach($values as $name) {
$myVals .= ',"'.( strlen($name) ? htmlspecialchars($name) : ' ').'"';
}
$_SESSION['myVals'] = $myVals;
On page2.php I need myVals to be placed into the following string:
$xls->addRow(Array("First Name","Last Name","Website","ID"));
There are supposed to be separate values for xls file headers. Currently if I put my string in it, it is interpreted as a single value.
$xls->addRow(Array($_SESSION['myVals']));
What am I missing?
Upvotes: 0
Views: 503
Reputation: 817198
Note that
array("First Name","Last Name","Website","ID")
is different from
array('"First Name","Last Name","Website","ID"')
The first one creates an array with four elements, while the second one creates an array with only one element as the commas are part of the string and not of the array()
statement. Calling array($_SESSION['myVals'])
is equivalent to the second example, because $_SESSION['myVals']
is only a string.
You should create a proper array:
$myVals = array();
foreach($values as $name) {
$myVals[] = strlen($name) ? htmlspecialchars($name) : ' ';
}
$_SESSION['myVals'] = $myVals;
and pass this one to $xls->addRow()
:
$xls->addRow($_SESSION['myVals']);
Upvotes: 1
Reputation: 70540
Why not store it as an array in page1?
Page1:
foreach($values as $name) {
$_SESSION['myVals'][] = strlen($name) ? htmlspecialchars($name) : ' ';
}
Page2:
$xls->addRow($_SESSION['myVals']);
Upvotes: 1