Bonjour,
J'ai une liste d'article avec des prix (en decimal) dans un fichier csv que je transforme dans un tableau a deux dimensions.
Quand j'affiche les valeurs j'ai bien mon prix de type 8,5 sans probleme.
echo $tab[x][8];
par contre si je fais :
echo $tab[x][8]*2;
J'obtiens la valeur 16 au lieu de 8,5 * 2 = 17
Voila mon pb et je comprend pas.
Voici ma classe de transformation. Je passe systematiquement par la fonction getTableauFiltrer($col,$val) pour afficher mes varticles.
Merci d'avance de votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 class fichierTableau { private $fichier; // true si fichier existe listearticle.csv private $tabLigne; // tableau contenant les lignes du fichier private $tableau; // tableau à deux dimension contenant tous les articles private $contenu_fichier; private $nbCol; // nombre de colonne private $nbLig; // nombre de lignes function fichierTableau() { $this->fichier = false; $this->tableau = array(); $this->tabligne = array(); $this->contenu_fichier = "vide"; if(file_exists("panier/listearticles.csv")) { $this->fichier=true; $this->tabLigne = file('panier/listearticles.csv'); //Place le contenu du fichier dans un tableau if(is_array($this->tabLigne)) //Si la variable $tabLigne est bien un tableau, on peut continuer { $this->contenu_fichier = ''; $li=1; foreach($this->tabLigne AS $ligne) { if($li>0) { $data = explode(";",$ligne); $this->nbCol = count($data); for($col=0;$col<count($data);$col++) { $this->tableau[$li-1][$col] = $data[$col]; }// Fin $li $this->contenu_fichier .= $this->tableau[$li-1][0]."<br>"; $li=$li+1; } // Fin foreach } // Fin is array $this->nbLig = $li - 1; } // Fin file exist } else { $this->fichier=false; $this->tabLigne = null; $this->contenu_fichier.="Fichier introuvale"; } } function destroy() { unset ($this->tabLigne); unset ($this->contenu_fichier); unset ($this->fichier); unset ($this->tableau); } function getInit() { return $this->fichier; } function getContenu() { return $this->contenu_fichier; } function getTableau() { return $this->tableau; } function getNbCol() { return $this->nbCol; } function getNbLig() { return $this->nbLig; } function getTableauFiltrer($col,$val) { $tf = array(); $xx=0; for($x=0;$x<$this->getNbLig();$x++) { if($this->tableau[$x][10]==1) { if($this->tableau[$x][$col]==$val) { for($y=0;$y<$this->getNbCol();$y++) { $tf[$xx][$y]=$this->tableau[$x][$y]; } $xx = $xx + 1; } } } return $tf; } }
Nicolas
Partager