Re: [PHP] Comparing array elements

2002-06-05 Thread Mark Heintz PHP Mailing Lists

Well, it sounds like something that could be done through the db
query, but if you want to use arrays, it'd be something like this...

$servers = arrray('s1','s2','s3','s4','s5');
$group1 = array('s1','s4','s5');

$in_group = array_intersect($servers, $group1);
$not_in_group = array_diff($servers, $group1);


mh.


On Wed, 5 Jun 2002, Chris Knipe wrote:

 hey everyone,

 Does anyone have and ideas of wisdom on how to compare arrays (mysql result
 sets) and group items based on if they exist in two or more arrays?

 For example:

 I have a table, with a list of servers:
 server1
 server2
 server3
 server4
 server5
 ...
 serverX

 I have a table that specifies which of the servers are grouped:
 group1
   server1
   server4
   server5

 Now, I want to compare group1 against the server list, and do something like
 the following:
 In group:
   server1
   server4
   server5

 Not in group:
   server2
   server3
   serverX



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Comparing array elements

2002-06-05 Thread Pushkar Pradhan

Never used those before, that's the way to do it! I think array_search and
in_array are suited for looking up one or two values.
 Well, it sounds like something that could be done through the db
 query, but if you want to use arrays, it'd be something like this...

 $servers = arrray('s1','s2','s3','s4','s5');
 $group1 = array('s1','s4','s5');

 $in_group = array_intersect($servers, $group1);
 $not_in_group = array_diff($servers, $group1);


 mh.


 On Wed, 5 Jun 2002, Chris Knipe wrote:

  hey everyone,
 
  Does anyone have and ideas of wisdom on how to compare arrays (mysql result
  sets) and group items based on if they exist in two or more arrays?
 
  For example:
 
  I have a table, with a list of servers:
  server1
  server2
  server3
  server4
  server5
  ...
  serverX
 
  I have a table that specifies which of the servers are grouped:
  group1
server1
server4
server5
 
  Now, I want to compare group1 against the server list, and do something like
  the following:
  In group:
server1
server4
server5
 
  Not in group:
server2
server3
serverX



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-Pushkar S. Pradhan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Comparing array elements

2002-06-05 Thread Pushkar Pradhan

You can use in_array or array_search.
 hey everyone,

 Does anyone have and ideas of wisdom on how to compare arrays (mysql result
 sets) and group items based on if they exist in two or more arrays?

 For example:

 I have a table, with a list of servers:
 server1
 server2
 server3
 server4
 server5
 ...
 serverX

 I have a table that specifies which of the servers are grouped:
 group1
   server1
   server4
   server5

 Now, I want to compare group1 against the server list, and do something like
 the following:
 In group:
   server1
   server4
   server5

 Not in group:
   server2
   server3
   serverX


 query



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-Pushkar S. Pradhan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php