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;
}
Of course, this won't work if you only want to count certain member variables, not all of them. But I'm sure it could be modified to do that too. :]