Parametre array dans fonction
Résolu
tigre198
Messages postés
54
Date d'inscription
Statut
Membre
Dernière intervention
-
tigre198 Messages postés 54 Date d'inscription Statut Membre Dernière intervention -
tigre198 Messages postés 54 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
j'ai trouvé fonctions qui calculte nombre de jours total entre deux dates sans compter weekend
et si je met
j'aurais resultat 8
mais comment on fait pour donner beaucoup de dates a cete fonction et avoir resultat total
par exemple si je done deux foix ces deux dates j'aurais résultat 16
j'ai essayé de déclarer array dans fonction mais toujours erreur:
j'ai trouvé fonctions qui calculte nombre de jours total entre deux dates sans compter weekend
<?php //The function returns the no. of business days between two dates and it skeeps the holidays function getWorkingDays($startDate,$endDate,$holidays){ //The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24 //We add one to inlude both dates in the interval. $days = (strtotime($endDate) - strtotime($startDate)) / 86400 + 1; $no_full_weeks = floor($days / 7); $no_remaining_days = fmod($days, 7); //It will return 1 if it's Monday,.. ,7 for Sunday $the_first_day_of_week = date("N",strtotime($startDate)); $the_last_day_of_week = date("N",strtotime($endDate)); //---->The two can be equal in leap years when february has 29 days, the equal sign is added here //In the first case the whole interval is within a week, in the second case the interval falls in two weeks. if ($the_first_day_of_week <= $the_last_day_of_week){ if ($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week) $no_remaining_days--; if ($the_first_day_of_week <= 7 && 7 <= $the_last_day_of_week) $no_remaining_days--; } else{ if ($the_first_day_of_week <= 6) $no_remaining_days--; //In the case when the interval falls in two weeks, there will be a Sunday for sure $no_remaining_days--; } //The no. of business days is: (number of weeks between the two dates) * (5 working days) + the remainder //---->february in none leap years gave a remainder of 0 but still calculated weekends between first and last day, this is one way to fix it $workingDays = $no_full_weeks * 5; if ($no_remaining_days > 0 ) { $workingDays += $no_remaining_days; } //We subtract the holidays foreach($holidays as $holiday){ $time_stamp=strtotime($holiday); //If the holiday doesn't fall in weekend if (strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate) && date("N",$time_stamp) != 6 && date("N",$time_stamp) != 7) $workingDays--; } return $workingDays; } ?>
et si je met
<?php $holidays=array("2006-12-25","2006-12-26","2007-01-01"); echo getWorkingDays("2006-12-22","2007-01-06",$holidays) ?>
j'aurais resultat 8
mais comment on fait pour donner beaucoup de dates a cete fonction et avoir resultat total
par exemple si je done deux foix ces deux dates j'aurais résultat 16
j'ai essayé de déclarer array dans fonction mais toujours erreur:
<?php Parse error: parse error, unexpected T_VARIABLE, expecting ')' ?>
A voir également:
- Parametre array dans fonction
- Fonction si et - Guide
- Remettre parametre usine pc - Guide
- Parametre dns - Guide
- Parametre windows - Guide
- Netflix paramètre compte - Guide
4 réponses
<?php // Connexion SQL [...] $nombreTotal = 0; $holidays = array("2006-12-25","2006-12-26","2007-01-01"); $sql = 'SELECT * FROM `taTable`'; $req = mysql_query($sql); while ($data = mysql_fetch_array($req)) { $nombreTotal += getWorkingDays($data['debut'], $data['fin'], $holidays); } ?>
echo getWorkingDays("2006-12-22","2007-01-06",$holidays)
Il manque un point virgule a la fin
mais comment on fait pour donner beaucoup de dates a cete fonction et avoir resultat total par exemple si je done deux foix ces deux dates j'aurais résultat 16
J'ai pas trop compris, mais tu peux faire:
$dt = getWorkingDays("2006-12-22","2007-01-06",$holidays); $dt += getWorkingDays("2007-12-22","2008-01-06",$holidays);
merçi de me répondre
en faite je veux partir d'une table my sql ou j'ai des milliers de lignes date_debut et dat_fin
par exemple
2008-01-01- / 2008-01-05
2008-01-01 / 2008-01-07
et donc grace a cette fonction je peux avoir comme résultat
nombre de jour total = 12;
j'ai essayé avec boucle for each avec des array mais sans résultat
j'espere t'a compris probleme;
sinon cool ton proverbe !!!!!
en faite je veux partir d'une table my sql ou j'ai des milliers de lignes date_debut et dat_fin
par exemple
2008-01-01- / 2008-01-05
2008-01-01 / 2008-01-07
et donc grace a cette fonction je peux avoir comme résultat
nombre de jour total = 12;
j'ai essayé avec boucle for each avec des array mais sans résultat
j'espere t'a compris probleme;
sinon cool ton proverbe !!!!!