Re: Unique Array
| From: | _lallous | Date: | Mon, 10 Sep 2001 13:12:09 +0000 |
| Subject: | Re: Unique Array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66729@lists.php.net to get a copy of this message | ||
and more practically your code get corrected to this:
for ($i = 0; $i<100; $i++)
{
$a[$i] = rand(0,9);
$test[]=$a[$i];
}
$ra = array_unique($test);
and your code get optimized to this: (mostly of the manual!;))
$numbers = range (0,9);
srand ((double)microtime()*1000000);
shuffle ($numbers);
"Cc Zona" <cczona@nospam.invalid> wrote in message
news:20010910114509.77443.qmail@pb1.pair.com...
> In article <F135FwtuYS6VnL9wtlo0000a9f7@hotmail.com>,
> mccanndee@hotmail.com (Deirdre Mc Cann) wrote:
>
> > for ($i = 0; $i<100; $i++){
> > $a[$i] = rand(0,9);
> > $test=$a[$i];
> > }
> >
> > $ra = array_unique($test);
> >
> > I keep getting an error saying $test is the incorrect type. Can someone
> > please explain why this doesn't work.
>
> $test is a string variable, not an array. To add elements to an array,
> either use $varname[], array_push(), or array_unshift().
>
> BTW, when an error message says that a variable is not the right type,
this
> is a good time to use gettype() and/or var_dump() in order to check that
> the variable really has the type and value(s) what that you expect.
>
> --
> CC