I have two arrays and I need the value from the first one to become the key for each row of an associative array. I think I stated that correctly. I have two arrays:
Array
(
[field_name0] => first_name
[field_name1] => mobile
[field_name2] => email
[field_name3] => last_name
)
and
Array
(
[1] => Array
(
[First Name] => Peter
[mobile] => 1234567890
[email] => email@email.com
[Last Name] => Griffin
)
[2] => Array
(
[First Name] => Al
[mobile] => 9874561230
[email] => test@test.com
[Last Name] => Bundy
)
)
I need the values from the first array to replace the values in each of the second arrays to look like this:
Array
(
[1] => Array
(
[first_name] => Peter
[mobile] => 1234567890
[email] => email@email.com
[last_name] => Griffin
)
[2] => Array
(
[first_name] => Al
[mobile] => 9874561230
[email] => test@test.com
[last_name] => Bundy
)
)
I have tried some bad attempts at some foreach
loops to accomplish this but it's getting a bit tricky for me. Please help. I am hoping I just overlooked a simple way to do this.
What I tried:-
foreach( $field_map as $origKey => $value ){
foreach($csvdata as $csvrow){
foreach($csvrow as $cKey => $cValue){
$newKey = $value;
$newArray[$newKey] = $cValue;
}
}
}