note 83097 added to function.array-walk
| From: | harmor at osu1 dot php dot net | Date: | Fri, 09 May 2008 19:23:31 +0000 |
| Subject: | note 83097 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139223@lists.php.net to get a copy of this message | ||
I just wanted a function to trim all the array elements. Here is a non-recursive version:
<?php
$data = array(' a',' b',' c d ');
function _trim(&$value)
{
$value = trim($value);
}
function array_trim($arr)
{
array_walk($arr,"_trim");
return $arr;
}
$arr = array_trim($data);
echo '<pre>';
var_dump($arr);
echo '</pre>';
$single = implode(' ',$arr);
echo '<pre>';
var_dump($single);
echo '</pre>';
?>
Output:
array(3) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(10) "c d"
}
string(14) "a b c d"
----
Server IP: 64.71.164.2
Probable Submitter: 66.27.49.42
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- https://master.php.net/note/edit/83097
Del: integrated -- https://master.php.net/note/delete/83097/integrated
Del: useless -- https://master.php.net/note/delete/83097/useless
Del: bad code -- https://master.php.net/note/delete/83097/bad+code
Del: spam -- https://master.php.net/note/delete/83097/spam
Del: non-english -- https://master.php.net/note/delete/83097/non-english
Del: in docs -- https://master.php.net/note/delete/83097/in+docs
Del: other reasons-- https://master.php.net/note/delete/83097
Reject -- https://master.php.net/note/reject/83097
Search -- https://master.php.net/manage/user-notes.php