Bonjour,

J'ai un bout de code, ou plutôt un pavé lol, et je suis certain qu'il y a moyen de réduire ce code en quelques lignes tant il y a de répétitions. ^^

Donc question: Comment réduire le code suivant pour chaque cas svp?
NB: le code est coupé, il n'y a pas 10fois mais 20 fois la même chose à chaque fois.

cas 1
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
/////////////////////////////////////////////////// 0
if(isset($_POST['heure0']))
$my_strh0=$_POST['heure0'];
else
$_POST['heure0'] = "00-00-00";
/////////////////////////////////////////////////// 1
if(isset($_POST['heure1']))
$my_strh1=$_POST['heure1'];
else
$_POST['heure1'] = "00-00-00";
 
if(!isset($a1))
$a1 = 0;
/////////////////////////////////////////////////// 2
if(isset($_POST['heure2']))
$my_strh2=$_POST['heure2'];
else
$_POST['heure2'] = "00-00-00";
 
if(!isset($a2))
$a2 = 0;
/////////////////////////////////////////////////// 3
if(isset($_POST['heure3']))
$my_strh3=$_POST['heure3'];
else
$_POST['heure3'] = "00-00-00";
 
if(!isset($a3))
$a3 = 0;
/////////////////////////////////////////////////// 4
if(isset($_POST['heure4']))
$my_strh4=$_POST['heure4'];
else
$_POST['heure4'] = "00-00-00";
 
if(!isset($a4))
$a4 = 0;
/////////////////////////////////////////////////// 5
if(isset($_POST['heure5']))
$my_strh5=$_POST['heure5'];
else
$_POST['heure5'] = "00-00-00";
 
if(!isset($a5))
$a5 = 0;
/////////////////////////////////////////////////// 6
if(isset($_POST['heure6']))
$my_strh6=$_POST['heure6'];
else
$_POST['heure6'] = "00-00-00";
 
if(!isset($a6))
$a6 = 0;
/////////////////////////////////////////////////// 7
if(isset($_POST['heure7']))
$my_strh7=$_POST['heure7'];
else
$_POST['heure7'] = "00-00-00";
 
if(!isset($a7))
$a7 = 0;
/////////////////////////////////////////////////// 8
if(isset($_POST['heure8']))
$my_strh8=$_POST['heure8'];
else
$_POST['heure8'] = "00-00-00";
 
if(!isset($a8))
$a8 = 0;
/////////////////////////////////////////////////// 9
if(isset($_POST['heure9']))
$my_strh9=$_POST['heure9'];
else
$_POST['heure9'] = "00-00-00";
 
if(!isset($a9))
$a9 = 0;
/////////////////////////////////////////////////// 10
if(isset($_POST['heure10']))
$my_strh10=$_POST['heure10'];
else
$_POST['heure10'] = "00-00-00";
 
if(!isset($a10))
$a10 = 0;
 ////////////////////////////////////////////////////
cas 2
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
/* VARIABLES */
$my_strh0=$_POST['heure0'];
$my_strh1=$_POST['heure1'];
$my_strh2=$_POST['heure2'];
$my_strh3=$_POST['heure3'];
$my_strh4=$_POST['heure4'];
$my_strh5=$_POST['heure5'];
$my_strh6=$_POST['heure6'];
$my_strh7=$_POST['heure7'];
$my_strh8=$_POST['heure8'];
$my_strh9=$_POST['heure9'];
$my_strh10=$_POST['heure10'];
cas 3
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
$h0=strtotime($my_strh0);
$h1=strtotime($my_strh1);
$h2=strtotime($my_strh2);
$h3=strtotime($my_strh3);
$h4=strtotime($my_strh4);
$h5=strtotime($my_strh5);
$h6=strtotime($my_strh6);
$h7=strtotime($my_strh7);
$h8=strtotime($my_strh8);
$h9=strtotime($my_strh9);
$h10=strtotime($my_strh10);
cas 4
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
if($h0 > $h1) {$a1=($h0-$h1);	}
if($h0 > $h2) {$a2=($h0-$h2); 	}
if($h0 > $h3) {$a3=($h0-$h3); 	}
if($h0 > $h4) {$a4=($h0-$h4); 	}
if($h0 > $h5) {$a5=($h0-$h5); 	}
if($h0 > $h6) {$a6=($h0-$h6); 	}
if($h0 > $h7) {$a7=($h0-$h7); 	}
if($h0 > $h8) {$a8=($h0-$h8); 	}
if($h0 > $h9) {$a9=($h0-$h9); 	}
if($h0 > $h10) {$a10=($h0-$h10);}
cas 5
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
if($h1 > $h0) {$a1=86400-($h1-$h0);  }
echo "Trajet".$my_strh1.""; 
@$date1 = getdate($h1);
 
if($h2 > $h0) {$a2=86400-($h2-$h0);  }
echo "Trajet".$my_strh2.""; 
@$date2 = getdate($h2);                
 
if($h3 > $h0) {$a3=86400-($h3-$h0);  }
echo "Trajet".$my_strh3.""; 
@$date3 = getdate($h3);
 
if($h4 > $h0) {$a4=86400-($h4-$h0);  }
echo "Trajet".$my_strh4.""; 
@$date4 = getdate($h4);
 
if($h5 > $h0) {$a5=86400-($h5-$h0);  }
echo "Trajet".$my_strh5.""; 
@$date5 = getdate($h5);
 
if($h6 > $h0) {$a6=86400-($h6-$h0);  }
echo "Trajet".$my_strh6.""; 
@$date6 = getdate($h6);
 
if($h7 > $h0) {$a7=86400-($h7-$h0);  }
echo "Trajet".$my_strh7.""; 
@$date7 = getdate($h7);
 
if($h8 > $h0) {$a8=86400-($h8-$h0);  }
echo "Trajet".$my_strh8.""; 
@$date8 = getdate($h8);
 
if($h9 > $h0) {$a9=86400-($h9-$h0);  }
echo "Trajet".$my_strh9.""; 
@$date9 = getdate($h9);
 
if($h10 > $h0) {$a10=86400-($h10-$h0);  }
echo "Trajet".$my_strh10.""; 
@$date10 = getdate($h10);
cas 6
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
$a1=$a1-3600;
$a2=$a2-3600;
$a3=$a3-3600;
$a4=$a4-3600;
$a5=$a5-3600;
$a6=$a6-3600;
$a7=$a7-3600;
$a8=$a8-3600;
$a9=$a9-3600;
$a10=$a10-3600;
cas 7
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
echo "Depart:";
//reconversion du timestamp en heure pr?format?e (ici H M)
echo strftime("%H:%M:%S",$a1);
echo strftime("%H:%M:%S",$a2);
echo strftime("%H:%M:%S",$a3);
echo strftime("%H:%M:%S",$a4);
echo strftime("%H:%M:%S",$a5);
echo strftime("%H:%M:%S",$a6);
echo strftime("%H:%M:%S",$a7);
echo strftime("%H:%M:%S",$a8);
echo strftime("%H:%M:%S",$a9);
echo strftime("%H:%M:%S",$a10);
D'avance merci.