Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

288
Vistas
Remove parent array from multidimensional array in php

using php how to get array result into below way,

 Array
    (
        [3] => Array
            (
                [15] => 15
                [16] => 16
                [17] => 17
                [18] => 18
                [19] => 19
            )

    )

how to convert above array into below format,

 Array
        (
            [0] => 15
            [1] => 16
            [2] => 17
            [3] => 18
            [4] => 19
        )
8 months ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

array_values() is your friend;

Presuming your array exists in a variable called $array;

$newArray = array_values($array[3]);
8 months ago · Santiago Trujillo Denunciar

0

you should use RecursiveArrayIterator to remove parent array

$arr = new RecursiveIteratorIterator(new RecursiveArrayIterator($multidimensional_array));
$new_arr = iterator_to_array($arr, false);
8 months ago · Santiago Trujillo Denunciar

0

try this, if you have more than one sub-array, it will work.

$arr = array(3 =>
        array
          ( 
           15  => 15,
           16 => 16,    
           17    => 17,  
           18    => 18,  
           19    => 19
          )
        );
    $new = array();
        foreach ($arr as $v){
            $new = array_merge($new , array_values($v)) ;
        }
echo "<pre>"; print_r($new);

Working Demo

8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos