fork download
  1. <?php
  2.  
  3. $courses = array((object) array("fullname" => "Nome 1"), (object) array("fullname" => "Nome 2"), (object) array("fullname" => "Nome 2"), (object) array("fullname" => "Nome 1"), (object) array("fullname" => "Nome 1"), (object) array("fullname" => "Nome 1"), (object) array("fullname" => "Nome 2"));
  4. ;$names = array();
  5.  
  6. foreach($courses as $key => $course) {
  7. if(!isset($names[$course->fullname])) {
  8. $names[$course->fullname] = 0;
  9. }
  10. $names[$course->fullname] += 1;
  11. $courses[$key]->fullname = $course->fullname. ' - ' .$names[$course->fullname];
  12. }
  13.  
  14. foreach($courses as $course) {
  15. echo $course->fullname. "\n";
  16. }
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Nome 1 - 1
Nome 2 - 1
Nome 2 - 2
Nome 1 - 2
Nome 1 - 3
Nome 1 - 4
Nome 2 - 3