I am using PHPExcel with Symfony 2 and showing the content of an excel file like this:
$users = array();
foreach($excel as $i=>$row) {
if($i !== 1) {
array_push($users,array(
'row'=>$i,
'name'=>$row['A'],
'lastname'=>$row['B']
//...and so on
));
}
}
Question :
How can I show the content using the row name instead of $row['A']..ect?
As $row['name']... I mean the name of the excel row.
Example:
A = name B = email...and so on... I would like to show the content like this:
$users = array();
foreach($excel as $i=>$row) {
if($i !== 1) {
array_push($users,array(
'row'=>$i,
'name'=>$row['name'],
'lastname'=>$row['surname']
//...and so on
));
}
}
I'm pretty sure that I answered this question barely a week ago.... assuming that row #1 contains your headers:
if($i == 1) {
$headers = $row;
} else {
$row = array_combine($headers, $row);
array_push($users,array(
'row'=>$i,
'name'=>$row['name'],
'lastname'=>$row['surname']
//...and so on
));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.