Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert array of single-element arrays to one a dimensional array

I have this kind of an array:

Array (     [0] => Array         (             [0] => 88868         )     [1] => Array         (             [0] => 88867         )     [2] => Array         (             [0] => 88869         )     [3] => Array         (             [0] => 88870         ) ) 

I need to convert this to one dimensional array. How can I do that?

For example like this..

Array (     [0] => 88868     [1] => 88867     [2] => 88869     [3] => 88870  ) 

Any php built in functionality is available for this array conversion?

like image 546
DEVOPS Avatar asked Jan 06 '12 08:01

DEVOPS


People also ask

What is array one-dimensional array?

Definition. A One-Dimensional Array is the simplest form of an Array in which the elements are stored linearly and can be accessed individually by specifying the index value of each element stored in the array.


1 Answers

For your limited use case, this'll do it:

$oneDimensionalArray = array_map('current', $twoDimensionalArray); 

This can be more generalized for when the subarrays have many entries to this:

$oneDimensionalArray = call_user_func_array('array_merge', $twoDimensionalArray); 
like image 119
deceze Avatar answered Sep 28 '22 03:09

deceze