![]() |
Determining the smallest of a group of variables.
Say I have a bunch of variables and want to figure out which one is the smallest. Obviously I can just load them into an array and do sortbyascending then take the first value and see which of the variables it matches, but I was wondering if there's a less convoluted way.
|
PHP Code:
|
Googie wanted a simpler way to do it besides using sort ascending dear Andrew.
|
PHP Code:
This what you looking for? |
I suggest mergesort or quicksort,
the effort of it is just rising by n log n for n as the natural size of the problem. |
I guess there's always:
PHP Code:
|
The thing is, I want to get the variable name, not its value. What I'm looking for is a simpler way of getting the variable name than getting the lowest value and then checking each variable if it matches the value, not a simpler way of getting the lowest value.
|
Quote:
|
Quote:
EDIT: Came up with a way to do it: PHP Code:
|
Ah, I completely misread, I thought you said numbers in an array, not a set of variables. In that case:
PHP Code:
|
Quote:
|
Quote:
|
Well...
PHP Code:
|
Owned :(
|
Quote:
PHP Code:
|
He sorted it, but did so in another variable, so the original array is untouched.
|
Quote:
|
sortascending() just sorts the array. It does not even return a sorted array. Something like:
PHP Code:
I guess you could make a sortascending2 and do: PHP Code:
PHP Code:
|
Quote:
|
| All times are GMT +2. The time now is 08:47 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.