Bonjour,
Je voudrais optimiser ce morceau de code
Y a-t-il possibilité de se servir d'une boucle ?
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 function createSess(){ //Valeur des données formulaires $_SESSION[$this->chp1]=$_POST[$this->chp1]; $_SESSION[$this->chp2]=$_POST[$this->chp2]; $_SESSION[$this->chp3]=$_POST[$this->chp3]; $_SESSION[$this->chp4]=$_POST[$this->chp4]; $_SESSION[$this->chp5]=$_POST[$this->chp5]; $_SESSION[$this->chp6]=$_POST[$this->chp6]; $_SESSION[$this->chp7]=$_POST[$this->chp7]; $_SESSION[$this->chp8]=$_POST[$this->chp8]; $_SESSION[$this->chp9]=$_POST[$this->chp9]; $_SESSION[$this->chp10]=$_POST[$this->chp10]; $_SESSION[$this->chp11]=$_POST[$this->chp11]; $_SESSION[$this->chp12]=$_POST[$this->chp12]; $_SESSION[$this->chp13]=$_POST[$this->chp13]; $_SESSION[$this->chp14]=$_POST[$this->chp14]; $_SESSION[$this->chp15]=$_POST[$this->chp15]; $_SESSION[$this->chp16]=$_POST[$this->chp16]; $_SESSION[$this->chp17]=$_POST[$this->chp17]; $_SESSION[$this->chp18]=$_POST[$this->chp18]; $_SESSION[$this->chp19]=$_POST[$this->chp19]; $_SESSION[$this->chp20]=$_POST[$this->chp20]; $_SESSION[$this->chp21]=$_POST[$this->chp21]; $_SESSION[$this->chp22]=$_POST[$this->chp22]; $_SESSION[$this->chp23]=$_POST[$this->chp23]; $_SESSION[$this->chp24]=$_POST[$this->chp24]; $_SESSION[$this->chp25]=$_POST[$this->chp25]; $_SESSION[$this->chp26]=$_POST[$this->chp26]; }
En fait j'ai une classe oµ chp1, chp2 ect correspond aux champs de ma table.
Donc en début de classe je dois déclarer chaques champs, ce qui me pousse à actualiser ma classe dès que je rajoute un champs.
Je voudrais le faire dynamiquement, compter les champs de ma table et construire ma boucle. Voilà pourquoi cette question
Merci à vous et bonne journée
Partager