I am trying to write a bunch of nested if statements that are somewhat as follows:
if (strcmp($data['reports'][$i][$j],$data['reports'][$i][$j-1])){
but as you all know, you have to write a separate if statement if it is 0, because 0-1 doesn’t exist.
if ($j == 0){
//First report, to prevent OBOB
echo "<br/><a href = ".$filename.">".$data['reports'][$i][$j]."</a>";
#-> You would have to write two more statements here to test for province...
}
if ($j >= 1){
//All subsequent reports
if (strcmp($data['reports'][$i][$j],$data['reports'][$i][$j-1])){
echo "<br/><a href = ".$filename.">".$data['reports'][$i][$j]."</a>";
#-> You would have to write two more statements here to test for province...
}
Now, imagine if you have to test other dependent values for sequential identicality?
It goes from 4 to 8 to 16 separate statements to just test for 4 of these…
So, I just had the idea to stuff crap into $j = -1.
$data['reports'][$i][-1]='aaaaaaaaaa';
// This would depend on the type of data you are
// comparing I suppose it could be zeros.
$data['provinces'][$i][-1]='aaaaaaaaa';
Is there a better solution?
Why don’t you just start your loop with 1 instead of 0? That is, instead of this:
do this:
It’s pointless to compare the first array element to the previous one anyway, so just skip it.