Construire un array de array
Bonjour,
Je cherche à construire un tableau de ce type :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
array(12) {
[0] => array(2) {
["id"] => float(31)
["name"] => string(6) "France"
}
}
[1] => array(2) {
["id"] => float(32)
["name"] => string(7) "Germany"
}
[2] => array(2) {
["id"] => float(36)
["name"] => string(7) "Holland"
}
}
} |
La difficulté c’est que je le construis lors d’une itération :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$i = 0;
foreach ($worksheet->getRowIterator() as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
$j = 0;
foreach ($cellIterator as $cell) {
if ($j < 2) {
//la construction du tableau
$data[$i][] = array( $name[$j] => $cell->getCalculatedValue() );
}
$j++;
}
$i++;
}
} |
Le résultat est le suivant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
array(12) {
[0] => array(2) {
[0] => array(1) {
["id"] => float(31)
}
[1] => array(1) {
["name"] => string(6) "France"
}
}
[1] => array(2) {
[0] => array(1) {
["id"] => float(32)
}
[1] => array(1) {
["name"] => string(7) "Germany"
}
}
[2] => array(2) {
[0] => array(1) {
["id"] => float(36)
}
[1] => array(1) {
["name"] => string(7) "Holland"
}
} |
Ça semble tout bête mais je n’arrive pas à sortir de ce problème.
Merci d’avance