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 codeIs it good for you?
$array = $_POST; for ($i=0;$i<count($array); $i++){ $array[$i]=my_function($array[$i]); }

12
Your code is good, but, take a look to array_map() php function.
1
Or even array_walk, which does exactly what softweb is asking for
http://us2.php.net/manual/en/function.array-walk.php
http://us2.php.net/manual/en/function.array-walk.php

3
array_walk($array, 'my_function');
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)