Re: Problem with object

From: Date: Fri, 10 May 2002 09:39:39 +0000
Subject: Re: Problem with object
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-96923@lists.php.net to get a copy of this message
> Now I want to resolve the hostname from ip adresses: > foreach ($aLines as $entry) > { if ($entry->host == "") > $entry->host = "Teststring"; > print $entry->host."\n"; // prints "Teststring" > } > > // Testoutput > foreach ($aLines as $entry) > { print $entry->host."\n"; // prints empty string! > } > > Why is host in the second loop empty again? Foreach returns a COPY of the contents... if you want to modify the contents use the key... eg: foreach ($aLines as $key=>$entry) { if ($aLines[$key]->host == "") $aLines[$key]->host = "Teststring"; print $aLines[$key]->host."\n"; // prints "Teststring" } That way your altering the master array and not the copy -- Dan Hardiker [dhardiker@staff.firstcreative.net] ADAM Software & Systems Engineer

« previous php.general (#96923) next »