Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-29-2006, 07:45 PM   PM User | #1
davehaz
Regular Coder

 
Join Date: Apr 2005
Posts: 388
Thanks: 0
Thanked 0 Times in 0 Posts
davehaz is an unknown quantity at this point
need help matching array elements

howdy,
I have two arrays $a & $b. they both started out with the same number of elements in each, $a consists of many duplicates example below.
[example]
$a =
[0]=> string(12) "BentGear.com"
[1]=> string(12) "BentGear.com"
[2]=> string(12) "BentGear.com"
[3]=> string(37) "BillBam.com - Bill Bam's Collectibles"
[4]=> string(37) "BillBam.com - Bill Bam's Collectibles"
[5]=> string(37) "BillBam.com - Bill Bam's Collectibles"
[6]=> string(37) "BillBam.com - Bill Bam's Collectibles"
[7]=> string(9) "Blair.com"
[8]=> string(7) "Buy.com"
[/example]
I used array_unique($a) to get it reduced to this.
[example]
[0]=> string(12) "BentGear.com"
[3]=> string(37) "BillBam.com - Bill Bam's Collectibles"
[7]=> string(9) "Blair.com"
[8]=> string(7) "Buy.com"
[/example]


array $b contains corresponding urls for $a.
[example]
[0]=> string(54) "http://www.shareasale.com/u.cfm?d=1719&m=7371&u=106368"
[1]=> string(54) "http://www.shareasale.com/u.cfm?d=1718&m=7371&u=106368"
[2]=> string(54) "http://www.shareasale.com/u.cfm?d=1717&m=7371&u=106368"
[3]=> string(54) "http://www.shareasale.com/u.cfm?d=1716&m=7371&u=106368"
[4]=> string(54) "http://www.shareasale.com/u.cfm?d=1671&m=7371&u=106368"
[5]=> string(54) "http://www.shareasale.com/u.cfm?d=1057&m=7371&u=106368"
[6]=> string(54) "http://www.shareasale.com/u.cfm?d=1283&m=5151&u=106368"
[7]=> string(54) "http://www.shareasale.com/u.cfm?d=1282&m=5151&u=106368"
[8]=> string(54) "http://www.shareasale.com/u.cfm?d=1281&m=5151&u=106368"
[9]=> string(53) "http://www.shareasale.com/u.cfm?d=889&m=5151&u=106368"
[10]=> string(53) "http://www.shareasale.com/u.cfm?d=448&m=5151&u=106368"
[11]=> string(53) "http://www.shareasale.com/u.cfm?d=301&m=5151&u=106368"
[12]=> string(53) "http://www.shareasale.com/u.cfm?d=294&m=5151&u=106368"
[13]=> string(53) "http://www.shareasale.com/u.cfm?d=293&m=5151&u=106368"
[14]=> string(53) "http://www.shareasale.com/u.cfm?d=197&m=5151&u=106368"
[15]=> string(53) "http://www.shareasale.com/u.cfm?d=196&m=5151&u=106368"
[16]=> string(53) "http://www.shareasale.com/u.cfm?d=113&m=5151&u=106368"
[17]=> string(53) "http://www.shareasale.com/u.cfm?d=112&m=5151&u=106368"
[18]=> string(52) "http://www.shareasale.com/u.cfm?d=13&m=5151&u=106368"
[19]=> string(52) "http://www.shareasale.com/u.cfm?d=12&m=5151&u=106368"
[20]=> string(44) "http://www.dpbolvw.net/click-1999005-4992712"
[21]=> string(47) "http://www.anrdoezrs.net/click-1999005-10389812"
[/example]

what I need to know is how can I match up the elements in $a with the corresponding url in $b?

any ideas?
tia.
davehaz is offline   Reply With Quote
Old 04-29-2006, 08:00 PM   PM User | #2
trib4lmaniac
Regular Coder

 
trib4lmaniac's Avatar
 
Join Date: Feb 2004
Location: Cornwall, UK
Posts: 535
Thanks: 0
Thanked 0 Times in 0 Posts
trib4lmaniac is an unknown quantity at this point
Why are $a and $b different sizes in the first place (9/22 elements)?
trib4lmaniac is offline   Reply With Quote
Old 04-29-2006, 08:01 PM   PM User | #3
cdwhalley.com
New Coder

 
Join Date: Apr 2006
Location: UK
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
cdwhalley.com is an unknown quantity at this point
You could put it all in one array, with the strings as the keys to the array?

PHP manual - Arrays
__________________
www.cdwhalley.com
cdwhalley.com is offline   Reply With Quote
Old 04-29-2006, 08:19 PM   PM User | #4
davehaz
Regular Coder

 
Join Date: Apr 2005
Posts: 388
Thanks: 0
Thanked 0 Times in 0 Posts
davehaz is an unknown quantity at this point
they both start out with 22, i just abbreviated $a for simplicity.
davehaz is offline   Reply With Quote
Old 04-29-2006, 08:38 PM   PM User | #5
davehaz
Regular Coder

 
Join Date: Apr 2005
Posts: 388
Thanks: 0
Thanked 0 Times in 0 Posts
davehaz is an unknown quantity at this point
I cant use one array as I need to get rid of the duplicates in $a, and the the values of $b are unique for each, so running array_unique does nothing for me when I have both values in one array.
davehaz is offline   Reply With Quote
Old 04-29-2006, 09:08 PM   PM User | #6
trib4lmaniac
Regular Coder

 
trib4lmaniac's Avatar
 
Join Date: Feb 2004
Location: Cornwall, UK
Posts: 535
Thanks: 0
Thanked 0 Times in 0 Posts
trib4lmaniac is an unknown quantity at this point
PHP Code:
$c array_unique(array_combine($b$a)); 
Not sure if that's exactly what you want though.
trib4lmaniac is offline   Reply With Quote
Old 04-29-2006, 09:16 PM   PM User | #7
davehaz
Regular Coder

 
Join Date: Apr 2005
Posts: 388
Thanks: 0
Thanked 0 Times in 0 Posts
davehaz is an unknown quantity at this point
thanks, I thought of that array_combine is only available in php 5, I am still using 4.
davehaz is offline   Reply With Quote
Old 04-29-2006, 09:23 PM   PM User | #8
trib4lmaniac
Regular Coder

 
trib4lmaniac's Avatar
 
Join Date: Feb 2004
Location: Cornwall, UK
Posts: 535
Thanks: 0
Thanked 0 Times in 0 Posts
trib4lmaniac is an unknown quantity at this point
From the php.net user comments:
PHP Code:
if (!function_exists('array_combine')) {
   function 
array_combine($a$b) {
       
$c = array();
       if (
is_array($a) && is_array($b))
           while (list(, 
$va) = each($a))
               if (list(, 
$vb) = each($b))
                   
$c[$va] = $vb;
               else
                   break 
1;
       return 
$c;
   }

trib4lmaniac is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:44 AM.


Advertisement
Log in to turn off these ads.