Reply to Re: [FAQ] Outputting alternate values (Was Re: How can I change every second row?)

Your name:

Reply:


Posted by Jerry Stuckle on 06/26/05 23:18

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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original 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

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