Okay, i have multidimensional array with keys and values:
[0] => Array
(
[0] => Consultant
[1] => Inv. num.
[2] => Order
[3] => Due
[12] => Currency
[13] => File
[21] => First name
[22] => Last name
[27] => ID
[28] => Birthdate
[29] => Postcode
[30] => City
[31] => Address
[36] => Mobile
[37] => Email
)
[1] => Array
(
[0] => 18642
[1] => 9376533321
[2] => 27.05.2019.
[3] => 28.06.2019.
[12] => Currency1
[13] => 109,43
[21] => Name1
[22] => Lastname1
[27] => 18977
[28] => Birhtdate1
[29] => Postcode1
[30] => City1
[31] => Address1
[36] => Mobile1
[37] => [email protected]
)
[2] => Array
(
[0] => 186625
[1] => 5638871123
[2] => 17.06.2019.
[3] => 03.07.2019.
[12] => Currency2
[13] => 235,33
[21] => Name2
[22] => Lastname2
[27] => 18954
[28] => Birthdate2
[29] => Postcode2
[30] => City2
[31] => Address2
[36] => Mobile2
[37] => mail@mail2
)
I would like to change key order in 2nd level of array, according to pattern: 21, 22, 27, 28, 29, 30, 31, 36, 37, 0, 1, 2, 3, 13, 12, but also, make the values rearrange with them.
So far, ive been able to change key pattern accordingly, but values order stays the same as they were in original array, and i want them to be rearranged together with keys. Also, my code transforms only last piece of the first level array, i would like to apply it on all subarrays:
$new_keys = array(21 => '', 22 => '', 27 => '', 28 => '', 29 => '', 30 => '', 31 => '', 36 => '', 37 => '', 0 => '', 1 => '', 2 => '', 3 => '', 13 => '', 12 => '');
foreach ($csvArray as $secondkey => $secondval) {
foreach ($secondval as $thirdkey => $thirdval) {
$final = array_combine(array_keys($new_keys), $secondval);
}
}
And i get output like this:
Array
(
[21] => 113243
[22] => 9013435433
[27] => 21.06.2019.
[28] => 09.07.2019.
[29] => SomeCurrency
[30] => 182,86
[31] => Some Name
[36] => Some Last Name
[37] => 0534343
[0] => 28.12.1981.
[1] => Some Zip Code
[2] => Some City Name
[3] => Some Address
[13] => Some Number
[12] => [email protected]
)
and i would like to get something like this:
[0] => Array
(
[21] => First name
[22] => Last name
[27] => ID
[28] => Birthdate
[29] => Postcode
[30] => City
[31] => Address
[36] => Mobile
[37] => Email
[0] => Consultant
[1] => Inv. num.
[2] => Order
[3] => Due
[13] => File
[12] => Currency
)
[1] => Array
(
[21] => Some name1
[22] => Some Last name1
[27] => 18732763
[28] => 28.06.2019.
[29] => Some post code1
[30] => Cityname1
[31] => SomeAddress1
[36] => Mobilenumber1
[37] => mail@mailaddress1
[0] => 0238244
[1] => 34345
[2] => Order1
[3] => 12.12.2019
[13] => 264,42
[12] => SomeCurrencyCode
)
etc.
Thank you.