![]() |
php wizards i have a question
Imagine i have and object with 50 values:
$my_obect->value_1 $my_obect->value_2 $my_obect->value_3 etc etc.. I want to add all values: $total = $my_object->value_1 + $my_object->value_2 etc etc.. Is there a faster way to do it? Replacing the number for a var ($my_object->value_$i or {$i} etc) in a while loop doesnt work as it would with normal vars.. |
I don't really use much OOP with PHP.....but if you used an array instead, you could just use the function array_sum()
|
Quote:
so value_1 > then v2,v3,v4,v5,v6 etc.. Thats why i need a way to loop through all these vars without having 50 lines of text.. I could move the data to an array and loop through there but i still need to compare the vars individually.. Hmm.. i could load it into an array.. do a sort.. and see if the highest number equals value_1 AND is unique in the array.... |
Quote:
PHP Code:
|
Quote:
|
Hey, this is how I'd do it:
Code:
/* |
All times are GMT -7. The time now is 07:11 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123