Jump to content

combing arrays within arrays


dadamssg87

Recommended Posts

I have two arrays, both with the same key values. I'd like to combine them. So for instance...

 

<?php
$array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah");
$array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz");

$array2['abcd'] = array('value3' => "three", 'value4' => "four");
$array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6");

function combine_arrays($array1,$array2)
{

//*combining*
return $single_array;
}

echo "<pre>";
print_r(combine_arrays($array1,$array2));
echo "</pre>";

/*
would produce 

['abcd'] = ( 'value1'  => "blah",
                 'value2'  => "blahblah",
                 'value3'  => "three",
                 'value4'  => "four" )

['efgh'] = ( 'value1' => "ha",
                 'value2' => "haha",
                'valuex'  => "xyz",
                'value3' => "hohoho",
                'value6' => "six6" )
*/
?>

 

What's the easiest way to do this?

Link to comment
https://forums.phpfreaks.com/topic/248850-combing-arrays-within-arrays/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.