tags:

views:

34

answers:

2

Im trying to reset $i to 0 and print the word margin...is this doable the way im trying to pull it off?

 class="customGal'.($i == '2' ? $i = '0' && 'margin' : NULL).'"

Thanks in advance.

+4  A: 

Why do it in such a "dirty" way? Why can't you simply add an if statement to check if $i is 2 and reset it to 0, and use the conditional expression for the print-out only (which is the way it it intended to be used)?

"Perl-nerd-style" programming (which involves very very short and complex concoctions) is charming, but really hard to understand later on...

Palantir
i thought it was a cool simple single-liner which i could make good use of later on.
Andy
unfortunately the conditional construct is a bit rigid. I bet you can find a strange way to force it to do what you want it to do, but it would become obscure. Anyway, if you want a recyclable single-liner... you can always make a function for it. Remember you can pass references to function, to have them act on external variables, for example to return the string, and at the same time update your $i.
Palantir
Sounds like a good idea. Thanks.
Andy
+2  A: 

You are doing it wrong way.
Take a habit using templates

So, in the getting data part write a readable code :

if ($i == 2) $row['margin'] == 'whatever';

And then in the template part:

class="customGal<?=$row['margin']?>"
Col. Shrapnel