R
R
Relapse2015-09-13 14:48:52
PHP
Relapse, 2015-09-13 14:48:52

How to remove nesting in an array?

There is such an array:

Array 
( 
  [0] => Array 
  (
    [0] => 6 
    [1] => 10
    [2] => 59
    [3] => 175
  ) 
  [1] => Array 
  ( 
    [0] => 896712
    [1] => 898015
    [2] => 898018
  ) 
  [2] => Array 
  ( 
    [0] => 900000
    [1] => 900001
  ) 
)

You need to make it like this:
Array 
( 
  [0] => 6 
  [1] => 10
  [2] => 59
  [3] => 175
  [0] => 896712
  [1] => 898015
  [2] => 898018
  [0] => 900000
  [1] => 900001
)

Keys are not needed in principle. It is important that the values ​​are in the same array.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2015-09-13
@Relapse

<?php
    $in = ;
    $out = [];
    array_walk_recursive($in, function($in) use (&$out) { $out[] = $in; });
    print_r($out);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question