You are here: Re: [FAQ] Outputting alternate values (Was Re: How can I change every second row?) « PHP Programming Language « IT news, forums, messages
Re: [FAQ] Outputting alternate values (Was Re: How can I change every second row?)

Posted by Jerry Stuckle on 06/27/05 14:28

R. Rajesh Jeba Anbiah wrote:
> Jerry Stuckle wrote:
>
>>R. Rajesh Jeba Anbiah wrote:
>>
>>>Q: How can I output alternate values from a set of values-list?
>>>A:
>>>
>>>
>>> 2. If you want just to flip-flop between two integers, use XOR logic:
>>><?php
>>>$flip_num = 1;
>>>$flop_num = 5;
>>>for($i=0, $n=$flip_num; $i<10; ++$i, $n ^= ($flip_num^$flop_num))
>>> echo $n;
>>>?>
>>
>>Way more complicated than necessary. Much better:
>>
>><?php
>> $flip_num = 1;
>> $flop_num = 5;
>> for($i=0; $i<10; $i++)
>> echo $i % 2 ? $flip_num : $flop_num;
>>?>
>>
>>KISS.
>
>
> Not really. Your logic requires an iterator variable $i; but none of
> the above logic requires such. So, the above logics can easily be
> incorporated while reading DB or using foreach or while loops.
>
> --
> <?php echo 'Just another PHP saint'; ?>
> Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com
>

Rajesh,

Your code also requires and iterator variable $i; additionally it
requires a second variable $n and uses a double xor logic.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация