Losing values with array_walk...
| From: | Per Lundkvist | Date: | Thu, 10 Apr 2003 09:30:43 +0000 |
| Subject: | Losing values with array_walk... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-143292@lists.php.net to get a copy of this message | ||
In my PHP class I have the array $this->aAllUsers that has usernames as key
and the value is an object with some values and I want to use the
first_name -value.
I want to build a new array, $this->aUsers, from this $this->aAllUsers that
will contain the first_names and look like:
Array
{
[0] => "Karl",
[1] => "Per",
[2] => "Sigmund",
[3] => "Lisa",
.
.
.
}
My script below works and $aArrayToBuild (reference to $this->aUsers) is
containing what I want all along to the end of the array_walk BUT when
array_walk is finished and the script continue with the next line, my
$this->aUsers is empty??? So it seems like $this->aUsers only keep it values
during the array_walk...??
My script:
// --------------------------------------------------
array_walk($this->aAllUsers, array($this,"setAnArray"), $this->aUsers);
function setAnArray($oValue,$key,&$aArrayToBuild){
$aArrayToBuild[$key] = $oValue->first_name;
}
// --------------------------------------------------
Somebody who knows what to do? I could make a regular loop but I don't want
to... ;-)