bonjour,

j'ai un formulaire avec du javascript permettant d'ajouter autant de ligne que le souhaite l'utilisateur (Année, Championnat, Classement).

Aussi, je me retrouve avec des éléments postés en nombre, je sais les traiter à l'unité mais pas en groupe.

Voici mon code actuellement, je mes les variables dans un tableau pour les traiter ensuite avec une boucle foreach :
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
 
if(!empty($_POST['item-year-1'])) 
{
							$chronological1 = array("year"=>$_POST['item-year-1'],"championship"=>$_POST['item-championship-1'],"classification"=>$_POST['item-classification-1']);
							$chronological_liste=array($chronological1);
						}
 
if(!empty($_POST['item-year-2'])) 
						{
							$chronological2 = array("year"=>$_POST['item-year-2'],"championship"=>$_POST['item-championship-2'],"classification"=>$_POST['item-classification-2']);
							$chronological_liste=array($chronological1,$chronological2);
						}	
 
						if(!empty($_POST['item-year-3'])) 
						{
							$chronological3 = array("year"=>$_POST['item-year-3'],"championship"=>$_POST['item-championship-3'],"classification"=>$_POST['item-classification-3']);
							$chronological_liste=array($chronological1,$chronological2,$chronological3);
						}

Comment puis-je automatiser la création du tableau avec une boucle for, plutôt que de mettre toutes les possibilités, actuellement je vais comme ça jusqu'à 10 ?

Merci d'avance pour votre aide.