3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array ( 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 => 'mail@mail.com', ), 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', ), ); $order = [21, 22, 27, 28, 29, 30, 31, 36, 37, 0, 1, 2, 3, 13, 12]; foreach($order as $index => $key){ $keys[$index] = $arr[0][$key]; } $values = array_slice($arr,1,2); // associate foreach($values as &$items){ foreach($order as $index => $key){ $new[$index] = $items[$key]; } $items = array_combine($keys, $new); } var_dump($values);
Output for 7.1.25 - 7.1.31, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(2) { [0]=> array(15) { ["First name"]=> string(5) "Name1" ["Last name"]=> string(9) "Lastname1" ["ID"]=> string(5) "18977" ["Birthdate"]=> string(10) "Birhtdate1" ["Postcode"]=> string(9) "Postcode1" ["City"]=> string(5) "City1" ["Address"]=> string(8) "Address1" ["Mobile"]=> string(7) "Mobile1" ["Email"]=> string(13) "mail@mail.com" ["Consultant"]=> string(5) "18642" ["Inv. num."]=> string(10) "9376533321" ["Order"]=> string(11) "27.05.2019." ["Due"]=> string(11) "28.06.2019." ["File"]=> string(6) "109,43" ["Currency"]=> string(9) "Currency1" } [1]=> &array(15) { ["First name"]=> string(5) "Name2" ["Last name"]=> string(9) "Lastname2" ["ID"]=> string(5) "18954" ["Birthdate"]=> string(10) "Birthdate2" ["Postcode"]=> string(9) "Postcode2" ["City"]=> string(5) "City2" ["Address"]=> string(8) "Address2" ["Mobile"]=> string(7) "Mobile2" ["Email"]=> string(10) "mail@mail2" ["Consultant"]=> string(6) "186625" ["Inv. num."]=> string(10) "5638871123" ["Order"]=> string(11) "17.06.2019." ["Due"]=> string(11) "03.07.2019." ["File"]=> string(6) "235,33" ["Currency"]=> string(9) "Currency2" } }

preferences:
197.05 ms | 406 KiB | 173 Q