|
Posted by Rik on 12/16/06 01:43
Geoff Berrow wrote:
> Message-ID: <3e4cb$458343c7$8259c69c$2192@news2.tudelft.nl> from Rik
> contained the following:
>
>> $array = split(' ',$string);
>> $newstring = '';
>> $rows = 3;
>> while($rows >= 1){
>> $newstring .= implode('
>> ',array_splice($array,0,floor(count($array)/$rows--))).'<br>';
>> }
>> echo $newstring;
>
> That's a bit complicated for you Rik...
>
> $array=explode(" ",$linestring);
> for($i=0;$i<count($array);$i++){
> echo(($i+1)%3===0)?$array[$i]." <br>\n":$array[$i]." ";
> }
Yup, for some reason I've decided I hate variable counters, don't know why
:-). It doesn't hurt to try different methods either.
Then again, your answer is flawed :P
It's not three (or #n) words in a row, but an arbitrary amount of words
split in #n rows.
That's a bit more complexity if we want to divide the remainder over the
rest of the rows... Easiest way to do that is to recalculate the number of
words we should use, hence the variable length splice.
--
Rik Wasmus
Navigation:
[Reply to this message]
|