How to apply an user function to each element of the array

posted by softweb on 2009-06-22 00:00:00
I have to apply a function to each element of the array, I have this code
$array = $_POST;
 
for ($i=0;$i<count($array); $i++){
	$array[$i]=my_function($array[$i]);
}
Is it good for you?
dail avatar
dail
12
Your code is good, but, take a look to array_map() php function.
49 answers - 0 questions
  Positive        Negative

Mitu
1
Or even array_walk, which does exactly what softweb is asking for
http://us2.php.net/manual/en/function.array-walk.php
1 answers - 0 questions
+ 1  Positive        Negative

livin52 avatar
livin52
3
 
array_walk($array, 'my_function');
 
6 answers - 0 questions
+ 1  Positive        Negative



Answer the question



Top Users
  • dail (12)
  • livin52 (3)
  • camu (3)
  • softweb (2)
  • Nadine (1)
  • Josware (1)
  • lfelipecr (1)
  • gregoriohc (1)
  • Mitu (1)
  • ryan714 (1)