Re: adding key-> value pair to an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> //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;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux