Re: adding info to an array?
| From: | Hawk | Date: | Thu, 01 Aug 2002 22:30:32 +0000 |
| Subject: | Re: adding info to an array? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110748@lists.php.net to get a copy of this message | ||
hahahaha, that was so stupid of me... should have put if (! $ra) { $ra =
array(); } but I seemed to have missed this.. lol :P
thanks for your help and sorry for being an idiot ;D
"Hawk" <hw2k@barrysworld.com> skrev i meddelandet
news:20020801214319.80796.qmail@pb1.pair.com...
> I'm a newbie at php, so dont tease me ;P
> first I have to input fields for $group and $amount
> and a textarea where you enter bla,blah,blabla etc
>
> $total = $amount*$group-1;
> $da = split (",", $textarea);
> for ($a = 1; $a <= $group; $a++) {
> print "<tr><td><table><tr><td>Group
> $a:<tr><td>";
> for ($b = 1; $b <= $amount; $b++) {
>
> $ra = array();
> $r = rand(0,$total);
> $check = in_array($r,$ra);
> if ($check == false) {
> $ra[] = "$r";
> print "<center>$da[$r] - $r<br>";
> }
> elseif ($check == true)
> $r = rand(0,$totalt);
> $b--; //
> }
>
> Maybe I'm doing completly wrong, but this is the way I was trying to solve
> it, just can't get it to work, even if I think it should :P
>
> "Aaron" <aaron_ott@hotmail.com> skrev i meddelandet
> news:20020801213216.74878.qmail@pb1.pair.com...
> > can we see the code?
> >
> > -aaron
> >
> > "Hawk" <hw2k@barrysworld.com> wrote in message
> > news:20020801211825.68352.qmail@pb1.pair.com...
> > > Tried that now, and with the same results
> > > print_r($ra); still only shows the last info inserted in the array :/
> > >
> > > "Aaron" <aaron_ott@hotmail.com> skrev i meddelandet
> > > news:20020801211307.65119.qmail@pb1.pair.com...
> > > > just assign the value to $ra[]
> > > >
> > > >
> > > > "Hawk" <hw2k@barrysworld.com> wrote in message
> > > > news:20020801210856.61486.qmail@pb1.pair.com...
> > > > > I have a for loop, and an if that checks something, and if true,
> it's
> > > > > supposed to add info to an array called $ra, but instead of adding
> it
> > to
> > > > the
> > > > > array it seems like it's overwriting it, currently I'm using
> $ra[$r]
> > =
> > > > > "$r"; where $r is a number..
> > > > > after the for } I put a print_r($ra); and it only prints the last
> > thing
> > > > that
> > > > > was added to the array. How do I solve this? Haven't used arrays
> much
> > so
> > > > I'm
> > > > > trying to learn, but it's not going very well :)
> > > > >
> > > > > Håkan
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>