How can I effectively get a helper array as a main array without a foreach loop?

Here is my array:

Array ( [0] => Array ( [same_key] => 1000 ) [1] => Array ( [same_key] => 1001 ) [2] => Array ( [same_key] => 1002 ) [3] => Array ( [same_key] => 1003 ) ) 

I want to get the following without using a foreach loop. Is it possible?

 Array ( [0] => 1000 [1] => 1001 [2] => 1002 [3] => 1003 ) 

Any tips?

+4
source share
2 answers

The following will do the trick

 $myArray = Array ( 0 => Array ( 'adfadf'=> 1000 ), 1 => Array ( 'adfadf' => 1001 ), 2 => Array ( 'adfadf' => 1002 ), 3 => Array ( 'adfadf' => 1003 ) ); $myArray = array_map('current', $myArray)); 
+4
source

you can do this with $array = array_map('current', $array);

living example

Output

enter image description here

+2
source

Source: https://habr.com/ru/post/1436208/


All Articles