Hi all, Is there a php function to merge two indexed arrays into one assoc array? I know I could write this function but I wanted to use the native function if it exists and I didn't see it on php.net It would work like: $KEY = Array('somekey'); $VALUE = Array('somevalue'); $ASSOC = make_assoc($KEY, $vALUE); // then $ASSOC looks like Array('somekey' => 'somevalue); Code (markup): -phil
Yeah, I guess it's really simple. It just seemed like Zend would have allready done it for me. Thanks for the input.
No problem - yeah i've thought the same way for little functions that i was SURE someone else had written and incorporated into php. I've spent too much of my life looking for these functions when I could have written them myself in about 30 seconds.
I thought I'd post this in case anyone was curious: /** * Converts two indexed arrays into an associative array of KEY=>VAlUE pairs * * @param array of key names $keys * @param array of values to map to key names $values * @return associative array like $array[$key] = $value */ function make_assoc($keys, $values) { $returnAssoc = array(); $valueCount = count($values); for($i = 0; $i < $valueCount; $i++) { $returnAssoc[$keys[$i]]=$values[$i]; } return $returnAssoc; } Code (markup):