note 68015 added to function.array-walk
| From: | legolas558dotsourceforgecommanet at osu1 dot php dot net | Date: | Mon, 10 Jul 2006 12:04:33 +0000 |
| Subject: | note 68015 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114632@lists.php.net to get a copy of this message | ||
to <ludvig dot ericson at gmail dot com>
I would solve the problem, which should be faster too.
<?php
function string_walk(&$string, $funcname, $userdata = null) {
for($i = 0; $i < strlen($string); $i++)
$string{$i} = call_user_func($funcname, $string{$i}, $i, $userdata);
}
// does nothing
function dummy_func($value, $position) {
return $value;
}
// adds a space
function spacing_func($value, $position) {
return $value.' ';
}
// converts each odd character to upper case
function upper_func($value, $position) {
if ($position % 2 == 0)
return $value;
else
return strtoupper($value);
}
$my_string = 'fruit';
string_walk(&$my_string, 'spacing_func');
echo $my_string;
// Ouput: f r u i t
$my_string = 'interesting';
string_walk(&$my_string, 'upper_func');
echo $my_string;
// Output: iNtErEsTiNg
?>
----
Server IP: 213.92.11.19
Probable Submitter: 151.44.90.54
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- http://master.php.net/note/edit/68015
Del: integrated -- http://master.php.net/note/delete/68015/integrated
Del: useless -- http://master.php.net/note/delete/68015/useless
Del: bad code -- http://master.php.net/note/delete/68015/bad+code
Del: spam -- http://master.php.net/note/delete/68015/spam
Del: non-english -- http://master.php.net/note/delete/68015/non-english
Del: in docs -- http://master.php.net/note/delete/68015/in+docs
Del: other reasons-- http://master.php.net/note/delete/68015
Reject -- http://master.php.net/note/reject/68015
Search -- http://master.php.net/manage/user-notes.php