Re: adding key-> value pair to an array
| From: | Yeti | Date: | Wed, 03 Dec 2008 09:24:21 +0000 |
| Subject: | Re: adding key-> value pair to an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284047@lists.php.net to get a copy of this message | ||
> //for each row I want to add percentage as new key->value pair
> // but it gives error 'Undefined variable:
> percentage'
> $row->$percentage = ($browseCount / $totalCount ) * 100;
Obviously you get the error because $percentage is not defined ..
I did not fully understand what you wanted.
Here is a list of what should work ...
#Set a variable percentage in $row
$row->percentage = ($browseCount / $totalCount ) * 100;
#Set a variable with name $percentage in $row
$percentage = ($browseCount / $totalCount ) * 100;
$row->$percentage = $percentage;