note 94053 added to function.array-map

From: Date: Wed, 14 Oct 2009 02:06:13 +0000
Subject: note 94053 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-161710@lists.php.net to get a copy of this message
Fixed a bug with array recursion. /** * arrayMap function. Customized array_map function which preserves keys/associate array indexes. Note that this costs a descent amount more memory (eg. 1.5k per call) * * @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) { $temp = $args; array_unshift($temp,$value); if(is_array($value)) { array_unshift($temp,$callback); $results[$key] = call_user_func_array(array('self','arrayMap'),$temp); } else { $results[$key] = call_user_func_array($callback,$temp); } } 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/94053 Del: integrated -- https://master.php.net/note/delete/94053/integrated Del: useless -- https://master.php.net/note/delete/94053/useless Del: bad code -- https://master.php.net/note/delete/94053/bad+code Del: spam -- https://master.php.net/note/delete/94053/spam Del: non-english -- https://master.php.net/note/delete/94053/non-english Del: in docs -- https://master.php.net/note/delete/94053/in+docs Del: other reasons-- https://master.php.net/note/delete/94053 Reject -- https://master.php.net/note/reject/94053 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161710) next »