I can do the match perfectly but what i also need to do is create a third
list of comma separated values that are in both
eg:
List 1 => 1,2,3,4,5,6,7,8 ,11
List 2 => 1,3,4,5,6,7,10, 23
Therefore
List 3 => 1,3,4,5,6,7
How do I populate this third list - I'm really stuck
"Craig Keightley" <do**@spam.me > wrote in message
news:42******** *************@n ews-text.dial.pipex .com... Ken that functions works a treat I have modified it to do waht i need it to do by including it in a loop of other lists and showing if they are a match or not
Many thanks
Craig
"Ken Robinson" <ke******@rbnsn .com> wrote in message news:11******** *************@z 14g2000cwz.goog legroups.com... Craig Keightley wrote: is it possible to compare acomma separated list aginst another
eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match??? the comparison is to check that if product a who supplies products
1,2,3,4,5 can be used instead of product b who supplies 3,5 as product a already supplies them
Here's a pure PHP solution I just created: <? function comp_csv($s1,$s 2) { $tmp1 = explode(',',$s1 ); $tmp2 = explode(',',$s2 ); $tmp3 = array_intersect ($tmp1,$tmp2); $smaller_array = (count($tmp1) < count($tmp2))?$ tmp1:$tmp2; $smaller_count = count($smaller_ array); $inboth = FALSE; if (count($tmp3) == $smaller_count) if (count(array_di ff($tmp3,$small er_array)) == 0) $inboth = TRUE; return($inboth) ; }
$csv1 = '1,2,3,4,5'; $csv2 = '3,5'; $x = comp_csv($csv1, $csv2); var_dump($x); ?> The function: 1) creates temporary arrays from the CSV strings 2) gets the intersection between the two arrays, which should have no more elements than the smaller array. It can have less. 3) if it has the same number of elements as the smaller array, it checks whether the it's elements are the same as those in the smaller array. If so, the returned value is set to TRUE
Ken BTW, followups changed to just comp.lang.php
1 2218
Craig Keightley wrote: I can do the match perfectly but what i also need to do is create a
third list of comma separated values that are in both
eg:
List 1 => 1,2,3,4,5,6,7,8 ,11 List 2 => 1,3,4,5,6,7,10, 23
Therefore
List 3 => 1,3,4,5,6,7
How do I populate this third list - I'm really stuck
The array_intersect () function returns an array of consisting of all
the elements that are in both arrays. The implode() function can be
used to turn that array back into a CSV string.
<?
$str_1 = '1,2,3,4,5,6,7, 8,11';
$str_2 = '1,3,4,5,6,7,10 ,23';
$str_3 =
implode(',',arr ay_intersect(ex plode(',',$str_ 1),explode(',', $str_2)));
echo $str_3;
?>
Ken This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Craig Keightley |
last post by:
is it possible to compare acomma separated list aginst another
eg comma list 1 => 1,2,3,4,5
comma list 2 => 3,5
can you check that 3 is in both, and 5 is in both, therfore they match???
the comparison is to check that if product a who supplies products 1,2,3,4,5
can be used instead of product b who supplies 3,5 as product a already
supplies them
|
by: Not Me |
last post by:
Hi,
I'm sure this is a common problem.. to create a single field from a
whole column, where each row would be separated by a comma.
I can do this for a specified table, and column.. and I've created a
function using VBA to achieve a more dynamic (and very slow) solution..
so I would like to implement it using a user defined function in sql server.
The problems I'm facing are, that I can't use dynamic sql in a
|
by: Pmb |
last post by:
I'm trying to learn the syntax for initializing objects in a comma separated
list. Below is an example program I wrote to learn how to do this (among
other things). While I understand how to initialize a primitive data type
with a comma separated list, e.g.
int a = { 11, 23, 43 };
I know how to initialize the example object's "student1" and "student2"
below, e.g.
|
by: Craig Keightley |
last post by:
I have a mysql database with a list of companies who supply specific
products
tblSuppliers (simplified)
sID | sName | goodsRefs
1 | comp name | 1,2,3,4,5
2 | company 2 | 2,4
|
by: Shawn Odekirk |
last post by:
Some code I have inherited contains a macro like the following:
#define setState(state, newstate) \
(state >= newstate) ? \
(fprintf(stderr, "Illegal state\n"), TRUE) : \
(state = newstate, FALSE)
This macro is called like this:
setState(state, ST_Used);
| |
by: Bob |
last post by:
I think this is very simple but I am having difficult doing it. Basically
take a comma separated list:
abc, def, ghi, jk
A list with only one token does not have any commas:
abc
The first letter of each token (abc) must not be a number. I am simply
trying to parse it to get an array of tokens:
abc
|
by: starman7 |
last post by:
I'm attempting a query that gathers product data for a particular
product id.
One of the items is designer(s) which can be more than one.
The product table has comma separated id's of the designers in the
designers table (which has fields like: id, fname, lname).
How can my select return the possibly several designers for a product,
with the rest of the row data, like price, name, etc.?
|
by: mahe23 |
last post by:
All,
How do One convert a comma separated column from a text file into rows in oracle. I have a scenario where the list of comma separated values changes dynamically.
It is like:
abc, ttt, 1,2,34,56,67,,
afg, ttt, 3,4,5,6,,,,,
|
by: mac |
last post by:
Hi,
I'm trying to write a fibonacci recursive function that will return
the fibonacci string separated by comma. The problem sounds like this:
-------------
Write a recursive function that creates a character string containing
the first n Fibonacci numbers - F(n) = F(n - 1) + F(n - 2), F(0) =
F(1) = 1 -, separated by comma. n should be given as an argument to
the program. The recursive function should only take one parameter, n,
and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |