Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
Create a multidimensional array based on number of values

i have an array that i get from a form with alot of fields, i need to order those fields under an array and that array under the ''main'' array. Ill post what i have, and what i need to get. WHAT I HAVE:

Array
(
    [perfil_area1] => Array
    (
        [0] => a2
        [1] => a3
    )

    [perfil_years] => Array
    (
        [0] => 2
        [1] => 4
    )

    [perfil_function] => Array
    (
        [0] => f1
        [1] => f4
    )

    [perfil_obs] => Array
    (
        [0] => teste1
        [1] => teste2
    )

    [perfil_company] => Array
    (
        [0] => emp1
        [1] => emp2
    )
)

This is what i need to be so i can turn it into a query: What i need

Array
(
    [0] => 
    (
        [perfil_area1] => a2
        [perfil_years] =>  2
        [perfil_function] =>  f1
        [perfil_obs] =>  teste1
        [perfil_company] =>  emp1
    )
    [1] =>
    (
        [perfil_area1] => emp2
        [perfil_years] =>  2
        [perfil_function] =>  f4
        [perfil_obs] =>  4
        [perfil_company] =>  a3
    )
)

i have tried with 2 foreach but i didnt manage to get it done. I have read Create a multidimensional array in a loop , how to create multidimensional array using a foreach loop in php? , create multidimensional array using a foreach loop , Converting an array from one to multi-dimensional based on parent ID values and some more but i still cant do it. Any tips on how to create it?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You just need to loop over the input array and build the new array

$new = [];
foreach ($in as $key=>$arr) {
    $new[0][$key] = $arr[0];
    $new[1][$key] = $arr[1];
}
over 4 years ago · Santiago Trujillo Relatório

0

<?php

$result = [];

for ($i=0; $i<count(reset($array)); $i++) {
    $result[] = array_combine(array_keys($array), array_column($array, $i));
}

Please read the manual for more details about array_combine(), array_keys() and array_column().

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda