RE: [PHP-DB] array_diff usage

From: Date: Mon, 02 Apr 2001 15:48:12 +0000
Subject: RE: [PHP-DB] array_diff usage
Groups: php.db 
Request: Send a blank email to php-db+get-8142@lists.php.net to get a copy of this message
I'm daft. I don't understand the PHP Manual. I have two arrays: Open[0] contains 1 2 3 4 5 Closed[0] contains 1 2 Now: $test = array_diff($Open, $Closed);
Given the setup you've described, I think you might actually want
       $test = array_diff($Open[0], $Closed[0]);
OK I'll try that.
$lines = count($test); print $lines; Gives me: 1 I thought it should be 3.
Seems appropriate, given the information you've provided. $Open and $Closed each have only one element (0).
While: for ($counter =0; $counter <= $lines -1; $counter++) {
        print $test[0];
} gives me "5".
This, on the other hand, makes me suspect that the arrays themselves don't actually contain what you think they do. How are you assigning the values you described at the top of your message?
I get them from a database by two select queries. Then I do $noOpened=mysql_num_rows($jobresult1);
       $noClosed=mysql_num_rows($jobresult2);
       $getlargest = strcmp($noOpened, $noClosed);
       switch ($getlargest) {
             case $getlargest > 0:
           $counttickets = $noOpened;
               while($sumOpen=mysql_fetch_row($jobresult1)) {                   $Open = $sumOpen;
                // DEBUG
                print $Open[0] . "<br>";
                             }
              while($sumClosed=mysql_fetch_row($jobresult2)) {                   $Closed = $sumClosed;
                // DEBUG
                print "c" . $Closed[0] . "<br>";
                            }
Which produces: 1 2 3 4 5 c1 c2 So the arrays are correctly set up (I think). Martin S.

« previous php.db (#8142) next »