...

View Full Version : need help matching array elements



davehaz
04-29-2006, 08:45 PM
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.

$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"

I used array_unique($a) to get it reduced to this.

[0]=> string(12) "BentGear.com"
[3]=> string(37) "BillBam.com - Bill Bam's Collectibles"
[7]=> string(9) "Blair.com"
[8]=> string(7) "Buy.com"



array $b contains corresponding urls for $a.

[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"


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

any ideas?
tia.

trib4lmaniac
04-29-2006, 09:00 PM
Why are $a and $b different sizes in the first place (9/22 elements)?

cdwhalley.com
04-29-2006, 09:01 PM
You could put it all in one array, with the strings as the keys to the array?

PHP manual - Arrays (http://uk2.php.net/manual/en/language.types.array.php)

davehaz
04-29-2006, 09:19 PM
they both start out with 22, i just abbreviated $a for simplicity.

davehaz
04-29-2006, 09:38 PM
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.

trib4lmaniac
04-29-2006, 10:08 PM
$c = array_unique(array_combine($b, $a));
Not sure if that's exactly what you want though.

davehaz
04-29-2006, 10:16 PM
thanks, I thought of that array_combine is only available in php 5, I am still using 4.

trib4lmaniac
04-29-2006, 10:23 PM
From the php.net user comments:


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;
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum