Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mdrakibhossainhawlader/ad59e54ac9b7b9fde417694f979814e6 to your computer and use it in GitHub Desktop.
Save mdrakibhossainhawlader/ad59e54ac9b7b9fde417694f979814e6 to your computer and use it in GitHub Desktop.
PHP: Array Map Associative
<?php
/**
* Converts a linear array to its associative equivalent.
*
* @param $array
* Linear array to process.
* @param $function
* Callback name to call against each value.
*
* @return array
* @see http://bugs.php.net/bug.php?id=34857
*/
function array_map_assoc(array $array, $function = NULL)
{
// array_combine() fails with empty arrays
empty($array) OR $array = array_combine($array, $array);
// Callback map
is_callable($function) AND $array = array_map($function, $array);
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment