Re: how to say "inverse your value" (to a boolean)?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> # before was $styles = array( 'even', 'odd' );
>>> # after new requirements it is...
>>> $styles = array( 'white', 'white', 'gray' );
>>> foreach($items as $item)
>>> {
>>> printf( '<li class="%s">%s</li>', current( $styles ), $item );
>>>
>>> next( $styles ) or  reset( $styles );
>>> }
>>>
>>>
>>>  +5000. I think is by far the most readable and flexible solution
>> suggested.
>> I also like it because it's PHPish -- it uses the features of the language
>> that were made-to-order for this problem.
>>
>
> Actually it's the wrong way to do it.
>
> Change the class names to "alternate1" and "alternate2" (or something else
> meaningful without being tied to a definition). That way when you set the
> colour for style "white" to "green" it doesn't result in confusion.
> Seriously though... this is nomenclature 101.


Good point, and thanks for the presentation-vs-content reality check. I'll
downgrade my vote to a more sober +4990, in consideration of the class names
in $styles.

Ben

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux