Pieter-Jan needed to add some features to a PHP-based site for managing student assessments. Students would complete projects, submit them, and then receive feedback from their peers. The number of peers providing feedback is variable, so the application has to manage that. Which, you might be thinking, "that sounds like not a big deal to manage," but for Pieter-Jan's predecessor, it seems like it may have been.

    if($i > '0') {
    if($i > '1') {
    if($i > '2') {

Each piece of student feedback contains four items. If two students give feedback, we create an array with 8. If three give feedback, we create an array with 12 items. There are seven more if statements exactly like these examples here.

And of course, how do we parse this? With a handy, dandy for loop:

for ($u = 0; $u < $i; $u = $u +1) {
 //remainder cut out

For any user u, the variables $w, $x, $y, and $z will contain the index of their required fields.

Apparently, the customer didn't like that the amount of feedback was capped at ten students, and wanted the app to support any arbitrary number of students. At that request, the original developer quit the project, and this became Pieter-Jan's problem.

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!