[Symfony2] Problème tableau 2 dimensions
Bonjour à toutes et à tous.
J'espère que vous allez très bien les amis :)
Mon problème que je ne sais pas d’où il vient, est que j'ai une fonction qui doit me faire des calculs sur un tableau de 2 dimensions mais ça ne marche pas :/
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public function calculer($nbrPrestations,$tab,$request)
{
for($i=0; $i<$nbrPrestations; $i++)
{
$tab[0][$i] = $request->get('petitDej'.$i);
$tab[1][$i] = $request->get('nuite'.$i);
$tab[2][$i] = $request->get('petitDej'.$i);
$tab[3][$i] = $request->get('dej'.$i);
$tab[4][$i] = $request->get('diner'.$i);
$tab[$i][5] = 0;
$tab[$i][5] = $tab[$i][0] + $tab[$i][1] + $tab[$i][2] + $tab[$i][3] + $tab[$i][4] ; /* Total de chaque prestation */
$tab[$nbrPrestations][0] += $tab[$i][0]; /* Total des petit déj */
$tab[$nbrPrestations][1] += $tab[$i][1]; /* Total des nuité */
$tab[$nbrPrestations][2] += $tab[$i][2]; /* Total des déj */
$tab[$nbrPrestations][3] += $tab[$i][3]; /* Total des diner */
$tab[$nbrPrestations][4] += $tab[$i][4]; /* Total des autres */
}
/* Total Global */
$tab[$nbrPrestation][5] = $tab[$nbrPrestation][0] + $tab[$nbrPrestation][1] + $tab[$nbrPrestation][2]
+ $tab[$nbrPrestation][3] + $tab[$nbrPrestation][4];
return $tab;
} |
Et dans une autre fonction où je fais l'appel, j'ai cela :
Code:
1 2
| $tab = array(); // déclaration du tableau
$tab = $this->calculer($nbrPrestations,$tab,$request); // affectation du résultat de la fonction calculer |
voila l'erreur que je reçois :
Citation:
ContextErrorException: Notice: Undefined offset: 1
Je vous remercie d'avance pour votre aide ;)