Sorting and foreach of MultiDimensional Array failing
| From: | James Tower) | Date: | Thu, 23 Aug 2001 21:47:40 +0000 |
| Subject: | Sorting and foreach of MultiDimensional Array failing | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-64182@lists.php.net to get a copy of this message | ||
In the following code, I'm reading a variable set of random numbers into a
multi-dimensional array.
The first iteration runs properly, but when I get to my 2nd+ iteration, I
get the following errors;
Warning: Wrong datatype in sort() call in /home/usrlinux/WWW/pballs.php on
line 18
Warning: Invalid argument supplied for foreach() in
/home/usrlinux/WWW/pballs.php on line 19
Is there a specific function for sorting and foreach statements of
multidimensional arrays? If so, why does it work properly for the first
interation,i.e. sort($num_array[1]) then subsequently fail on
sort($num_array[2])
Thank you in advance!
<?
srand ((double) microtime() * 1000000);
$totnum = 5;
$min = 1;
$max = 49;
$tickcount=1;
$num_array = array();
array_push($num_array, array());
echo "Now Generating $tickets Tickets!<br>\n";
while ($tickcount <= $tickets)
{
while ( $numbercount < $totnum)
{
$num_array[$tickcount][] = rand($min,$max);
$numbers = array_unique($num_array[$tickcount]);
$numbercount = count($num_array[$tickcount]);
}
sort($num_array[$tickcount]);
foreach($num_array[$tickcount] as $val)
{
echo "<img src=ball.php?text=$val&color=grey>  ";
}
$pb[$tickcount] = rand(1,42);
print "<img src=ball.php?text=$pb[$tickcount]&color=red>";
$tickcount++;
}
?>
___________________________
James C. Montz
James Tower
http://www.jamestower.com
jcmontz@jamestower.com