[PHP] Help with matchng strings
I have two list one is listA and the other is listB I would like to take the values in listB and compare them with listA if any of them match then I what to create a new list listC and put the values that match in it. If they do not match I want the values to go into listD. I have been messing with this for three days and have not been able to get it to work. I have used foreach statements and array_search but what ever I try I just can't seam to get it. What I need is something like below. Could somebody please help. If LISTB MATCHES LISTA If NO Match LISTA LISTB Make LISTC Make LISTD test1 test4 test4 test1 test2 test6 test6 test2 test3 test8 test8 test3 test4 test5 test5 test7 test6 test9 test7 test8 test9 -- Best regards, rdkurth mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with matchng strings
array_intersect() will give you listC directly. Just feed it list A and B. Then you can take a copy of listA and do a foreach on the array_keys() of listC and unset() them. Now this copy with the removed elements becomes your listD -Rasmus On Sun, 25 Aug 2002 [EMAIL PROTECTED] wrote: I have two list one is listA and the other is listB I would like to take the values in listB and compare them with listA if any of them match then I what to create a new list listC and put the values that match in it. If they do not match I want the values to go into listD. I have been messing with this for three days and have not been able to get it to work. I have used foreach statements and array_search but what ever I try I just can't seam to get it. What I need is something like below. Could somebody please help. If LISTB MATCHES LISTA If NO Match LISTA LISTB Make LISTC Make LISTD test1 test4 test4 test1 test2 test6 test6 test2 test3 test8 test8 test3 test4 test5 test5 test7 test6 test9 test7 test8 test9 -- Best regards, rdkurth mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] Help with matchng strings
Hello Rasmus, Ok I understand the array_intersect and have gotten that to work. I just don't understand the second part using the foreach and unset(). this is what I have it gives me three separate list $listA=tester1 tester2 tester3 tester4 tester5 tester6 tester7 tester8 tester9; $listB=tester4 tester6 tester8; $arraylistA=explode( ,$listA); $arraylistB=explode( ,$listB); $result = array_intersect ($arraylistA, $arraylistB); foreach($arraylistA as $valueA){ echo ValueA: $valueAbr\n; } echo br; foreach($arraylistB as $valueB){ echo ValueB: $valueBbr\n; } echo br; foreach($result as $valueC){ echo ValueC: $valueCbr\n; } Sunday, August 25, 2002, 4:48:36 PM, you wrote: RL array_intersect() will give you listC directly. Just feed it list A and RL B. Then you can take a copy of listA and do a foreach on the array_keys() RL of listC and unset() them. Now this copy with the removed elements RL becomes your listD RL -Rasmus RL On Sun, 25 Aug 2002 [EMAIL PROTECTED] wrote: I have two list one is listA and the other is listB I would like to take the values in listB and compare them with listA if any of them match then I what to create a new list listC and put the values that match in it. If they do not match I want the values to go into listD. I have been messing with this for three days and have not been able to get it to work. I have used foreach statements and array_search but what ever I try I just can't seam to get it. What I need is something like below. Could somebody please help. If LISTB MATCHES LISTA If NO Match LISTA LISTB Make LISTC Make LISTD test1 test4 test4 test1 test2 test6 test6 test2 test3 test8 test8 test3 test4 test5 test5 test7 test6 test9 test7 test8 test9 -- Best regards, rdkurth mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Best regards, rdkurthmailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with matchng strings
$lista=array(1,2,3,4,5,6,7,8,9); $listb=array(4,6,8); $listc=array_intersect($lista,$listb); $listd=array_diff($lista,$listb); Op maandag 26 augustus 2002 01:48, schreef Rasmus Lerdorf: array_intersect() will give you listC directly. Just feed it list A and B. Then you can take a copy of listA and do a foreach on the array_keys() of listC and unset() them. Now this copy with the removed elements becomes your listD -Rasmus On Sun, 25 Aug 2002 [EMAIL PROTECTED] wrote: I have two list one is listA and the other is listB I would like to take the values in listB and compare them with listA if any of them match then I what to create a new list listC and put the values that match in it. If they do not match I want the values to go into listD. I have been messing with this for three days and have not been able to get it to work. I have used foreach statements and array_search but what ever I try I just can't seam to get it. What I need is something like below. Could somebody please help. If LISTB MATCHES LISTA If NO Match LISTA LISTB Make LISTC Make LISTD test1 test4 test4 test1 test2 test6 test6 test2 test3 test8 test8 test3 test4 test5 test5 test7 test6 test9 test7 test8 test9 -- Best regards, rdkurth mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php