UYOU
嘿伙计,我跳过了数组中的一些项目,但希望我的结构是正确的;)$firstArray = [ [ 'CIDADES' => 'PONTA GROSSA', 'PERIODO' => '12:00 - 18:00', 'ID' => 'Z8932', 'END' => 'AV VSC DE MAUA,, ALT', 'CONTRATO' => '7947488', 'AREA' => 'AR01', 'ASSINANTE' => 'DAVI', 'BAIRRO' => 'OFICINAS', 'OBS' => ['Agendamento par'], 'TEL RES' => '42410435', ], [ 'CIDADES' => 'PONTA GROSSA', 'PERIODO' => '08:00 - 12:00', 'ID' => 'Z7526', 'END' => 'R P1000, FD', 'CONTRATO' => '799644', 'AREA' => 'AR01', 'ASSINANTE' => 'DAVI', 'BAIRRO' => 'BEATRIZ', 'OBS' => ['Agendamento'], 'TEL RES' => '42988674761', ], [ 'CIDADES' => 'PONTA GROSSA', 'PERIODO' => '08:00 - 12:00', 'ID' => 'Z0979', 'END' => 'R J93, FD', 'CONTRATO' => '79490', 'AREA' => 'AR01', 'ASSINANTE' => 'FERNANDES REIS', 'BAIRRO' => 'UVARANAS', 'OBS' => ['Agendamentoente'], 'TEL RES' => '4289986', ],];$secondArray = [ [ 'id' => 1, 'table' => 'id_operacao', 'sheet' => 'CIDADES', ], [ 'id' => 2, 'table' => 'horario', 'sheet' => 'PERIODO', ], [ 'id' => 3, 'table' => 'tipo_wo', 'sheet' => 'TIPO DE SERVICO', ], [ 'id' => 4, 'table' => 'tecnico_id', 'sheet' => 'ID', ], [ 'id' => 5, 'table' => 'contrato', 'sheet' => 'CONTRATO', ], [ 'id' => 6, 'table' => 'roteamento', 'sheet' => 'AREA', ], [ 'id' => 7, 'table' => 'endereco', 'sheet' => 'END', ], [ 'id' => 8, 'table' => 'nome_cliente', 'sheet' => 'ASSINANTE', ],];//I guess this is what you were missing most$oldKeysToNewKeys = array_combine( array_column($secondArray, 'sheet'), array_column($secondArray, 'table'));foreach ($firstArray as $key => $firstArrayElements) { $newFirstArrayElement = []; foreach ($firstArrayElements as $oldKey => $value) { //You could add checks to avoid errors when keys are not set etc.. $newKey = $oldKeysToNewKeys[$oldKey]; $newFirstArrayElement[$newKey] = $value; } $firstArray[$key] = $newFirstArrayElement;}//There you go!var_dump($firstArray);