Re: Comparing arrays confusion

From: Date: Mon, 26 Apr 2004 15:39:30 +0000
Subject: Re: Comparing arrays confusion
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184665@lists.php.net to get a copy of this message
"Alex Hogan" <Alex.Hogan@AlliedElec.com> wrote in message news:F63DEC4D37ACD41183C700508B95574F0F88D1D3@exchsrvr.alliedelec.com... > I am having trouble properly comparing a couple of arrays. (Actually three > arrays) > > Class array > Array ( [] => Active / Semiconductor [1] => Cable & Wire [2] => Enclosure > [3] => Relay & Solenoid [4] => Industrial Control [5] => Audio, Warning, > Video, & Security [6] => Connectors [7] => Cable Assembly [8] => Power > Supplies [9] => Buyout / Specials ) > > Subclass array > Array ( [] => Passive Component [1] => Optoelectronic [2] => Connectors [3] > => Boards/Printed Circuit Board (PCB) [4] => Thermal Management ) > > Percentages arrayArray ( [] => 0.13 [1] => 2.22 [2] => 32.35 [3] => 15.58 > [4] => 0.17 [5] => 18.32 [6] => 1.29 [7] => 0.11 [8] => 16.89 [9] => 11.88 ) This is $percentages. See below. > > > The class array and the subclass array are the first comparison that I'm > doing to produce; > > Intersect arrayArray ( [6] => Connectors ) This is $intersect. See below. > > Now I have the difference; > > Intersect difference arrayArray ( [] => Passive Component [1] => > Optoelectronic [3] => Boards/Printed Circuit Board (PCB) [4] => Thermal > Management ) > > What I want to do from here is to associate the intersection of the two > arrays with the percentage array; > > Intersect combined arrayArray ( [Connectors] => 1.29 ) > > Then have the remaining array members from the subclass array display with a > 0 value. I have created an associative array with the class and subclass > arrays. > > How do I display the subclass array with the value from the percentages > array on the intersection of the subclass and class? I hope I understand your problem correctly. Is this what you're looking for?: $intersectCombined = array(); foreach ($intersect as $key => $value) { $intersectCombined[$value] = $percentages[$key]; } Do a print_r($intersectCombined) to see if the result is the desired one. Regards, Torsten > > > > alex hogan

« previous php.general (#184665) next »