![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
salad tossing sig guy
Join Date: Apr 2002
Location: mrthumbs*gmail.com
Posts: 11,702
|
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.. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
|
I don't really use much OOP with PHP.....but if you used an array instead, you could just use the function array_sum()
__________________
Skype variuscr - Email varius AT gmail |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 | |
salad tossing sig guy
Join Date: Apr 2002
Location: mrthumbs*gmail.com
Posts: 11,702
|
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.... |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 | |
Confirmed User
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
|
Quote:
PHP Code:
__________________
Skype variuscr - Email varius AT gmail |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
salad tossing sig guy
Join Date: Apr 2002
Location: mrthumbs*gmail.com
Posts: 11,702
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Join Date: May 2001
Location: http://topadultblogs.com/
Posts: 137
|
Hey, this is how I'd do it:
Code:
/* * Gets the name of the member variable with the highest value * * Returns the name of the variable or false on failure */ function getHighestVariableName($obj) { if (!is_object($obj)) return false; // get all the variables of the class $values = get_object_vars($obj); $field = false; $highest = null; // loop through the variables, try to find the highest one foreach ($values as $key => $value) { if ($value > $highest) { $highest = $value; $field = $key; } } return $field; }
__________________
![]() NastyLittle.com - trade with an established adult blog |
![]() |
![]() ![]() ![]() ![]() ![]() |