Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Crear matriz multidimensional a partir de múltiples matrices en PHP

Tengo dos matrices:

 Array ( [0] => label [1] => data ) Array ( [0] => 1 [1] => 2 )

Y necesito fusionarlos en una matriz como esta:

 Array ( [0] => Array ( [label] => 1 [data] => 2 ) )

Yo he tratado:

 for ($i=0; $i < count($inputs); $i++) { $new = array($cols[$i] => $inputs[$i]); $data[] = $new; }

Cualquier ayuda es bienvenida ;)

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Simplemente puede usar array_combine :

Crea una matriz usando una matriz para claves y otra para sus valores

 $arr1 = array(0 => 'label', 1 => 'data'); $arr2 = array(0 => 1, 1 => 2); $arr3 = array_combine($arr1, $arr2); print_r($arr3);

Resultado:

 Array ( [label] => 1 [data] => 2 )

Intentalo

over 4 years ago · Santiago Trujillo Report

0

Puedes hacerlo así si quieres usar un bucle.

 $array1 = ['label', 'data']; $array2 = [1, 2]; $array_merged = []; foreach($array1 as $key => $value) { $array_merged[$value] = $array2[$key]; } var_dump($array_merged);

http://sandbox.onlinephpfunctions.com/code/c4e5bc71df53ebdafb0a54d43c3eadb4ea4cd241

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!