Re: array_diff usage

From: Date: Mon, 02 Apr 2001 15:23:43 +0000
Subject: Re: array_diff usage
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-8176@lists.php.net to get a copy of this message
On Monday 02 April 2001 15:41, you wrote: > > -----Original Message----- > > From: Martin Skjoldebrand [mailto:chimbis@skjoldebrand.org] > > Sent: Saturday, March 31, 2001 10:52 PM > > To: php-db@lists.php.net > > Subject: [PHP-DB] array_diff usage > > > > > > 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'm getting them from a database. Two SELECT queries one get the open tickets, one get the closed ones. $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>"; } I'm going to manipulate both arrays, so I copy them to "backups" DEBUG lines produce: 1 2 3 4 5 c1 c2 HTH, Martin S.

« previous php.db (#8176) next »