You haven't reset $numbercount, so on the second iteration you never enter
the while loop and so $num_array[2] is never actually created. Remember
$num_array[2] is simply an element of the top level array. It isn't an array
until you make it one, regardless of what the previous elements are.
Remember ... there are no multi-dimensional arrays in php, just arrays that
can contain arrays (that can contain arrays, etc.)

Tim Ward

        ----------
        From:  Montz, James C. (James Tower) [SMTP:[EMAIL PROTECTED]]
        Sent:  23 August 2001 22:48
        To:  Php-General (E-mail)
        Subject:  Sorting and foreach of MultiDimensional Array failing

        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>&nbsp;&nbsp";
          }
         $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 
        [EMAIL PROTECTED] 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to