Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Tablica dynamiczne wymiary
Forum PHP.pl > Forum > Przedszkole
poprzednik
Kod:
  1. $tasksout = array();
  2. $tasksout['counthours'] = 0;
  3. foreach($tasks as $task){
  4. $user = $userManager->findUserBy(array('id' => $task->getUserId()));
  5. $tasksout[$task->getid()]['task_id'] = $task->getTaskid();
  6. $tasksout[$task->getid()]['username'] = $user->getUsername();
  7. $tasksout[$task->getid()]['userid'] = $task->getUserId();
  8. $tasksout[$task->getid()]['hours'] = $task->gethours();
  9. $tasksout['countperuser'][$task->getUserId()] += $task->gethours();
  10. $tasksout['counthours'] += $task->gethours();
  11. }

notacja która zwraca internala:
Notice: Undefined offset:(tu liczba zależna od [$task->getUserId())
Chodzi o tą linię:
  1. $tasksout['countperuser'][$task->getUserId()] += $task->gethours();


Jak się pozbyć tej notacji i zrobić by banglało?
trueblue
  1. if(!isset($tasksout['countperuser'][$task->getUserId()])
  2. $tasksout['countperuser'][$task->getUserId()]=0;
  3. $tasksout['countperuser'][$task->getUserId()] += $task->gethours();


lub

  1. if(!isset($tasksout['countperuser'][$task->getUserId()])
  2. $tasksout['countperuser'][$task->getUserId()]=$task->gethours();
  3. else
  4. $tasksout['countperuser'][$task->getUserId()] += $task->gethours();
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.