Reply to Re: Help understanding a script

Your name:

Reply:


Posted by Ben Bacarisse on 03/20/06 19:16

On Sun, 19 Mar 2006 23:52:54 +0000, newbie wrote:

> I was wondering if anyone can help explain this code for me
>
> [CODE]
> <table width="<?= $TABLE_WIDTH ?>" border="0" cellspacing="0"
> cellpadding="0">
> <?php
> for ($x=1; $x<=pow(2, $COLUMNS); $x++) {
> // open the row
> printf('<tr>');
>
> // draw each of the columns in this row...
> for ($y=1; $y<=$COLUMNS; $y++) {
>
> // begin with a default style
> $style = "line";
> $value = "";
>
> // Determine the content for the data cells (if there is any)
> // and add the underline style always
> if (($x % pow(2, $y)) == pow(2, $y-1)) {
> [/CODE]
>
> From what I try to understand this code
>
> [CODE]
> if (($x % pow(2, $y)) == pow(2, $y-1)) {
> [/CODE]
>
> would be a smaller number divided by a larger number and would give the
> remainder. I have tried a smaller number divided by a larger number in a
> simple script, but the remainder always seems to equal the smaller
> number.

Not always. $x is often bigger than pow(2, $y). It looks like code you'd
use to layout the draw in an N-round knockout tournament (N == $COLUMNS):

The cells selected by that test alternate in the first column, are one in
four of the second, one in eight in the third and so on... All lined up
so no row has more than one selected cell. It is quite clever but it
could do with a comment or two, though!

What is it actually for?

--
Ben.

[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

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