Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a multidimensional array of data called $orderRecords and another array which has fields that I need called $keys

$orderRecords looks like this:

Array
(
[0] => Array
    (
        [fullAddress] => 123 MAIN ST
        [recordID] => 77891455
        [First Name] => XXX
        [filler1] => 
        [Last Name] => XXX
        [filler2] => 
        [Full Address] => 123 MAIN ST
        [City] => PEORIA
        [State] => AZ
        [5 Digit Zip Code] => 85382
        [Zip Code Extension] => 2549
        [filler3] => 
        [filler4] => 
        [Make] => FORD
        [Model] => F250 SUPER DUTY CREW CAB
        [Class Code] => FULL SIZE
        [Mileage Code] => 
        [Fuel Type] => DIESEL
        [Make Type] => DOMESTIC
        [Vin] => XXX
        [Phone] => 
        [Year] => 2004
        [Purchase Date] => 20070101
        [Last Validation Date] => 20110703
        [Radius] => .00
    )

[1] => Array
    (
        [fullAddress] => 123 ELM ST
        [recordID] => 77953928
        [First Name] => XXX
        [filler1] => 
        [Last Name] => XXX
        [filler2] => 
        [Full Address] => 123 ELM ST
        [City] => PEORIA
        [State] => AZ
        [5 Digit Zip Code] => 85382
        [Zip Code Extension] => 5157
        [filler3] => 
        [filler4] => 
        [Make] => FORD
        [Model] => EXPLORER
        [Class Code] => FULL SIZE SUV
        [Mileage Code] => 
        [Fuel Type] => FLEXIBLE FUEL
        [Make Type] => DOMESTIC
        [Vin] => XXXX
        [Phone] => 
        [Year] => 2004
        [Purchase Date] => 20070101
        [Last Validation Date] => 20110501
        [Radius] => .00
    )

   )

There's a lot more arrays in that array but that shows the structure.

Here is what my $keys array looks like:

Array
(
[First Name] => 0
[Zip Code Extension] => 1
[Last Name] => 2
[Full Address] => 3
[City] => 4
[State] => 5
[5 Digit Zip Code] => 6
[zipRadius] => 7
[filler1] => 8
[filler2] => 9
[filler3] => 10
[filler4] => 11
)

I am using the following code to pull out only the keys I need from $orderRecords:

            foreach($orderRecords as $key => $data) {

                $orderData[$key] = array_intersect_key($data, $keys);

            }

The intersecting is working and in my new array ($orderData) I only get the keys that were in $keys. The problem I am having is that it is duplicating some of the records. Not all just some of the records are ending up in the $orderData array more than once.

I have confirmed that I do not have duplicates in my $orderRecords array. I also have confirmed that the counts for the $orderRecords and $orderData are the same. So they end up with the same amount of records but some are duplicated which means I am missing some records from the original array in the final array.

I am really not sure what I am doing wrong here.

Any insight would be great.

Thanks!

share|improve this question
 
When you say there are duplicates, how do you determine this? It seems that you are removing the one key recordID that would uniquely identify a records. –  Mike Brant Jan 23 '13 at 19:57
 
My Full Address is also unique. I am using that to find the duplicates. Thanks –  Sequenzia Jan 23 '13 at 19:58
 
@Sequenzia I suppose that if you try to write example code to search duplicates, you will understand, what is the reason of your results. Try to set $key[recordID]=77 and watch this param at possible dups. It seems that you do have duplicates. –  shukshin.ivan Jan 23 '13 at 20:59
 
This ended up being a different problem. Thanks for the help –  Sequenzia Jan 25 '13 at 2:49
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.