Re: Re: Troubles from the newb again

From: Date: Sat, 10 Mar 2007 07:29:03 +0000
Subject: Re: Re: Troubles from the newb again
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-250192@lists.php.net to get a copy of this message
Jeff Taylor wrote:
Is it possible to just add a value to the existing? here is my current script: foreach ($newarray as $name) {
    $newarray[$name] = $name->currentInitiative =
rand(1,$name->GetInitiative())); } // sort array by ranking (initiative) sort($newarray,SORT_NUMERIC); can I change the $newarray[$name] to something to represent the current element and just add the value to it? I might be able to work around it then
That's not the problem. Your problem is that you are trying to use an object ($name) as the key of an array. You can't do this. Array keys must be a scalar value, that is to say a 'normal' value (essentially a string or a number). The object in $name probably has some unique value that represents that particular instance. Use that instead of the object itself. -Stut

« previous php.general (#250192) next »