note 47964 added to function.array-walk
| From: | neo-blue at gmx dot net | Date: | Tue, 07 Dec 2004 11:54:30 +0000 |
| Subject: | note 47964 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81485@lists.php.net to get a copy of this message | ||
I need to put all values of an array into one string line, separated with commas. That's what
I'm trying:
// inserting commas between array values
function array2string($item1, $key, &$string)
{
if ($string == '') {
$string = "$item1";
} else {
$string .= ",$item1";
}
}
// calling the function for each array value
array_walk($myarray, 'array2string', $myarray_string);
As you can see, I use pass-by-reference for the $myarray_string variable. The problem is that the
value is getting passed by I never get the value back from the function. Thus, the value of the
$myarray_string is still the same as before calling the "array2string".
Is this a PHP bug?
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47964
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47964&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47964&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47964&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47964&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47964&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47964&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47964&report=yes
Search -- http://master.php.net/manage/user-notes.php