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 27 28
| // option 1
class Csv{
private $data;
function __construct( $colonnes , $donnees ){
$this->data = array_combine( $colonnes , $donnees );
}
function __get( $colonne ){
return $this->data[ $colonne ];
}
}
$f = fopen( $monFichier , 'r' );
$colonnes = fgetcsv( $f , 0 , ';' );
$lignes = array();
while( $donnees = fgetcsv( $f , 0 , ';' ) ){
$lignes[] = new Csv( $colonnes , $donnees );
}
//option 2
$f = fopen( $monFichier , 'r' );
$colonnes = fgetcsv( $f , 0 , ';' );
$lignes = array();
while( $donnees = fgetcsv( $f , 0 , ';' ) ){
$ligne = array_combine( $colonnes , $donnees );
$lignes[] = (object) $ligne;
} |
Partager