note 94008 added to function.array-map

From: Date: Sun, 11 Oct 2009 22:33:07 +0000
Subject: note 94008 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-161642@lists.php.net to get a copy of this message
Wrote up my own key preservation function for array mapping. It allows n arguments to be passed, and should be easy enough to follow if you need to make any mods. If you've got any thoughts let me know. /** * arrayMap function. Customized array_map function which preserves keys/associate array indexes. * * @access public * @param callback $callback Callback function to run for each element in each array. * @param mixed $arr1 An array to run through the callback function. * @param array $array Variable list of array arugments to run through the callback function. * @return array Array containing all the elements of $arr1 after applying the callback function to each one, recursively, maintain keys. */ function arrayMap($callback,$arr1) { $results = array(); $args = array(); if(func_num_args()>2) $args = (array) array_shift(array_slice(func_get_args(),2)); foreach($arr1 as $key=>$value) { if(is_array($value)) { array_unshift($args,$value); array_unshift($args,$callback); $results[$key] = call_user_func_array(array('self','arrayMap'),$args); } else { array_unshift($args,$value); $results[$key] = call_user_func_array($callback,$args); } } return $results; } ---- Server IP: 69.147.83.197 Probable Submitter: 173.32.155.180 ---- Manual Page -- http://www.php.net/manual/en/function.array-map.php Edit -- https://master.php.net/note/edit/94008 Del: integrated -- https://master.php.net/note/delete/94008/integrated Del: useless -- https://master.php.net/note/delete/94008/useless Del: bad code -- https://master.php.net/note/delete/94008/bad+code Del: spam -- https://master.php.net/note/delete/94008/spam Del: non-english -- https://master.php.net/note/delete/94008/non-english Del: in docs -- https://master.php.net/note/delete/94008/in+docs Del: other reasons-- https://master.php.net/note/delete/94008 Reject -- https://master.php.net/note/reject/94008 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161642) next »