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!
recordID
that would uniquely identify a records. – Mike Brant Jan 23 '13 at 19:57