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

122
Views
PHP - Cambiar el comienzo de una matriz

Me gustaría cambiar el comienzo de mi matriz en PHP. Actualmente tengo:

 Array ( [0] => Bla## [1] => Bla## [2] => Bla## [3] => Bla## [4] => Bla## [5] => Bla##

pero yo quiero

 Array ( [6] => Bla## [7] => Bla## [8] => Bla## [9] => Bla## [10] => Bla## [11] => Bla##

array_splice($array, 14, 0, 'Bla##'); para insertar un valor en un índice específico de mi matriz, pero si uso esto, mi matriz comienza desde 0 y no desde 6.

¡Gracias por adelantado!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

$shift = 6; $array = array_combine(range($shift, count($array)+$shift-1), $array);
over 4 years ago · Santiago Trujillo Report

0

Simplemente mueva todas las posiciones de la matriz hacia adelante en 6 0->6, 1->7, etc.

 $array = [Bla##,Bla##,Bla##,Bla##,Bla##,Bla##]; $newarray = array(); // Shifted array for ($i=0; $i < count($array);$i++) { $newarray[$i+6] = $array[$i]; }
over 4 years ago · Santiago Trujillo Report

0

Puedes usar array_walk() :

 $n = 6; array_walk($arr, function($value) use (&$x, &$n) {$x[$n] = $value; $n++;});

Demostración de PHP

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!