note 87262 added to function.array-walk

From: Date: Thu, 27 Nov 2008 00:08:22 +0000
Subject: note 87262 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-147016@lists.php.net to get a copy of this message
Unfortunately I spent a lot of time trying to permanently apply the effects of a function to an array using the array_walk function when instead array_map was what I wanted. Here is a very simple though effective example for those who may be getting overly frustrated with this function... <?php $fruits = array("Lemony & Fresh","Orange Twist","Apple Juice"); print_r($fruits); echo '<br />'; function name_base($key) { $name2 = str_replace(" ", "_", $key); $name3 = str_replace("&", "and", $name2); $name4 = strtolower($name3); echo $name4.'<br />'; return $name4; } echo '<br />'; $test = array_map('name_base', $fruits); $fruits_fixed = $test; echo '<br />'; print_r($fruits_fixed); ?> ---- Server IP: 209.41.74.194 Probable Submitter: 68.56.255.165 ---- Manual Page -- http://www.php.net/manual/en/function.array-walk.php Edit -- https://master.php.net/note/edit/87262 Del: integrated -- https://master.php.net/note/delete/87262/integrated Del: useless -- https://master.php.net/note/delete/87262/useless Del: bad code -- https://master.php.net/note/delete/87262/bad+code Del: spam -- https://master.php.net/note/delete/87262/spam Del: non-english -- https://master.php.net/note/delete/87262/non-english Del: in docs -- https://master.php.net/note/delete/87262/in+docs Del: other reasons-- https://master.php.net/note/delete/87262 Reject -- https://master.php.net/note/reject/87262 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147016) next »