|
Posted by Geoff Berrow on 01/21/06 23:53
Message-ID: <bpadnUgDvvR9FU_enZ2dnUVZ_sSdnZ2d@comcast.com> from JackM
contained the following:
><snip Geoff's code that worked>
>
>Thanks Geoff. Does the fact that you rewrote nearly the entire code mean
>that I had butchered it completely?
Heh... dunno really, I've coded similar things before and usually find
nested loops work well. No disrespect to your code, but it was easier
to knock out something I'd done before than try to work through your
logic.
>
>I can follow most of what you did but there are two lines that are
>foreign to me:
>
>$spaces=($lines%$cols>0)? 1 : 0;
The question mark is the ternary operator. It's a shorter way of
writing if/else. '$lines%$cols' divides $lines by $cols and gives the
remainder. If there is a remainder the result will be greater than 0 and
$spaces is set to 1. If there is no remainder it is set to zero.
I could have written
if($lines%$cols>0){
$spaces= 1;
}
else{
$spaces=0;
}
>$rows=floor($lines/$cols)+$spaces;
If we divide $lines by $cols we get the number of rows. The function
floor just rounds it down. So if you have 9 lines and 4 columns the
answer would be two. In fact the answer is two until you have 12 lines.
However, if it doesn't divide exactly you need another row. That being
the case, $spaces is already set to one and so we have the correct
number.
>
>Can you give me a quick idea of what those do? They are a little beyond
>my PHP vocabulary right now. Thanks for your help.
No problem.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Navigation:
[Reply to this message]
|