php - Is there any array function by which I can get the expected result? -


this question has answer here:

is there array function can expected result?

my array

$a = array( [0] => array( 'id' => 6 ), [1] => array( 'id' => 5 ), [2] => array( 'id' => 8 ), [3] => array( 'id' => 4 ), ); 

result expected

$a = array( [0] => 6, [1] => 5 , [2] => 8 , [3] => 4, ); 

i can using foreach loop. searching array function ..

strictly, yes, there function array_walk():

array_walk($a, function (&$value) {     $value = $value['id']; }); 

but foreach loop more efficient in case:

foreach ($a &$value) {     $value = $value['id']; } 

a foreach loop has little overheads compared array_walk, has create , destroy function call stack on each invokation of callback function.

note in each case, $value passed reference (using & operator). means array changed in place, no copying of array necessary.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -