<?php
$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"));
foreach($courses as $key => $course) {
if(!isset($names[$course->fullname])) { $names[$course->fullname] = 0;
}
$names[$course->fullname] += 1;
$courses[$key]->fullname = $course->fullname. ' - ' .$names[$course->fullname];
}
foreach($courses as $course) {
echo $course->fullname. "\n";
}
PD9waHAKCiRjb3Vyc2VzID0gYXJyYXkoKG9iamVjdCkgYXJyYXkoImZ1bGxuYW1lIiA9PiAiTm9tZSAxIiksIChvYmplY3QpIGFycmF5KCJmdWxsbmFtZSIgPT4gIk5vbWUgMiIpLCAob2JqZWN0KSBhcnJheSgiZnVsbG5hbWUiID0+ICJOb21lIDIiKSwgKG9iamVjdCkgYXJyYXkoImZ1bGxuYW1lIiA9PiAiTm9tZSAxIiksIChvYmplY3QpIGFycmF5KCJmdWxsbmFtZSIgPT4gIk5vbWUgMSIpLCAob2JqZWN0KSBhcnJheSgiZnVsbG5hbWUiID0+ICJOb21lIDEiKSwgIChvYmplY3QpIGFycmF5KCJmdWxsbmFtZSIgPT4gIk5vbWUgMiIpKTsKOyRuYW1lcyA9IGFycmF5KCk7Cgpmb3JlYWNoKCRjb3Vyc2VzIGFzICRrZXkgPT4gJGNvdXJzZSkgewoJaWYoIWlzc2V0KCRuYW1lc1skY291cnNlLT5mdWxsbmFtZV0pKSB7CgkJJG5hbWVzWyRjb3Vyc2UtPmZ1bGxuYW1lXSA9IDA7Cgl9CgkkbmFtZXNbJGNvdXJzZS0+ZnVsbG5hbWVdICs9IDE7CgkkY291cnNlc1ska2V5XS0+ZnVsbG5hbWUgPSAkY291cnNlLT5mdWxsbmFtZS4gJyAtICcgLiRuYW1lc1skY291cnNlLT5mdWxsbmFtZV07Cn0KCmZvcmVhY2goJGNvdXJzZXMgYXMgJGNvdXJzZSkgewoJZWNobyAkY291cnNlLT5mdWxsbmFtZS4gIlxuIjsKfQ==