php - Merge two associative arrays by pushing their values into a new array -


i have following 2 arrays:

$arrfoo = array(     'a' => 12,     'b' => 17, ); $arrbar = array(     'a' => 9,     'c' => 4, ); 

and want resulting array this:

$arrresult = array(     'a' => array ( 12, 9 ),     'b' => array ( 17 ),     'c' => array ( 4 ), ); 

is there smart way achieve without using foreach?

<?php  $arrfoo = array(     'a' => 12,     'b' => 17, ); $arrbar = array(     'a' => 9,     'c' => 4, );  $arrresult = array_merge_recursive($arrfoo, $arrbar);  var_dump($arr);  ?> 

with array_merge_recursive can merge arrays in way you're asking for. http://php.net/manual/en/function.array-merge-recursive.php


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -