try this:
Main Topics
Browse All TopicsHi ...
I got this warning when testing an old script to newer php version (4.4.7)
Warning: array_rand() [function.array-rand]: First argument has to be an array in C:\xampp\htdocs\mlm\system
And below is the excerpt codes where it uses array_rand() ... I hope one can help me modify it to makes the script works on php 4.4.7 ... Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
In your current code, $bb2r is only created and initialised the first time that mysql_fetch_array succeeds. If it does not succeed, then not on is $bb2r not an array, it doesn't exist at all.
Try declaring the array just before your while loop starts:
$i2r = 0;
$bb2r=array(); # <--- array declared
while ( $row = mysql_fetch_array( $choose ) )
This ensures that what you pass to array_rand() is an array even if no results are returned by mysql_fetch_array.
Wouw ... it goes more complex than I thought unfortunately .. :-(
At first, as @angelIII suggest. I put:
$i2r = 0;
$bb2r=array();
But I really have no idea what/how to array $bb2r.
As @Roonaan suggest, I put this at the end:
print_r($bb2r)
.. and it only prints >> Array ( )
@siliconbrit .. by having a look at the codes, can you suggest me what to array for $bb2r
Anyone ... ?
@angelIII
wouw ... never thought it's gonna be that simple .. :p
Okay I put $bb2r=array();
and retest the script but then it shows this error
Warning: array_rand() [function.array-rand]: Second argument has to be between 1 and the number of elements in the array in C:\xampp\htdocs\mlm\system
Any more suggestion bro?
Here's as I add the array():
@Roonaan
This script is actually working on php 4.1.0 (I tried using PHPTriad and it's totally working).
But next when I use XAMPP (php 4.4.7 which is also the version of php used in my hosting) there are several issues need to be fixed .. and this array_rand() is one of them.
So .. what/how you want me to validate the query ... sorry for all of my limitations in advance ... just trying to learn something by doing .. :-)
Business Accounts
Answer for Membership
by: RoonaanPosted on 2008-02-18 at 02:59:43ID: 20918912
You have not defined $bb2r as an array in this snippet. When your query returns 0 rows, it will never be available as an array.
What does print_r($bb2r) show?
-r-