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

207
Views
Formato de matriz de Laravel

Tengo una matriz creada a partir de una consulta elocuente que se ve así:

 [['ctry' => 'US', 'subs' => 10], ['ctry' => 'AU', 'subs' => 25], ....]

Y quiero convertirlo a:

 ['US' => 10, 'AU' => 25, ...]

array_map , call_user_func_array , laravel's flatten sin éxito. Gracias

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si está obteniendo datos del modelo, puede usar el método pluck() :

 $model = Model::pluck('subs', 'ctry')->toArray();
over 4 years ago · Santiago Trujillo Report

0

Una posible solución puede ser

 <?php $sample_array = [['ctry' => 'US', 'subs' => 10], ['ctry' => 'AU', 'subs' => 25]]; # more elements in the array $result_array = []; foreach ($sample_array as $key => $value) { array_push($result_array, [$value['ctry'] => $value['subs']]); } print_r($result_array);
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!