Snippet Name: Combining two arrays into one Description: A quick bit of code for combining two arrays into one. Also see:» Pre-populated List of Countries » Array of all US states » Search array elements for a substring » Create a drop down menu from an array ... » Unset unkown array element » Parse RSS into array » Quickly sort associative arrays » Recursively traverse array » Combining three arrays into one » Check if array is associative » Unique Array function » Pick Randomly from Array » HEX to RGB array » Filter Empty Array Elements Comment: (none) Language: PHP Highlight Mode: PHP Last Modified: March 16th, 2009
Description: A quick bit of code for combining two arrays into one.
Also see:» Pre-populated List of Countries » Array of all US states » Search array elements for a substring » Create a drop down menu from an array ... » Unset unkown array element » Parse RSS into array » Quickly sort associative arrays » Recursively traverse array » Combining three arrays into one » Check if array is associative » Unique Array function » Pick Randomly from Array » HEX to RGB array » Filter Empty Array Elements
<?PHP FUNCTION array_combine($arr1, $arr2) { $out = ARRAY(); $arr1 = ARRAY_VALUES($arr1); $arr2 = ARRAY_VALUES($arr2); FOREACH($arr1 AS $key1 => $value1) { $out[(string)$value1] = $arr2[$key1]; } RETURN $out; } ?>