Christian Mayer's Weblog

PHP: array_map_assoc()

With array_map() you only can walk through the keys of an given array. Why is there no array_map_assoc()? For walking through an associative array to map also the keys not only the values.

function array_map_assoc($func, $ar){
	$rv = array();
	foreach($ar as $key => $val){
		$func($key, $val);
		$rv[$key] = $val;
	return $rv;

$assoc_array1 = array('x' => 'y', 'z' => 'abc');
$assoc_array2 = array_map_assoc(function(&$key, &$val){ $key = ':'.$key; }, $assoc_array1);

Posted on .
Categories: Programming, Productivity
Tags: PHP, Array, assoc, associative, associatively, Map, Development

Categories | RSS Feed | Usage | Imprint
Copyright © 2006 by