|
Posted by Joe on 11/27/05 00:49
That worked perfect, thank you very much.
Next problem is for me to calculate:
Total and avg. value of the 25 highest paid workers
Total and avg. value of the 50 highest paid workers
I can do it by looping through the array, is there a way to do it in one
command?
"Ewoud Dronkert" <firstname@lastname.net.invalid> skrev i en meddelelse
news:8p2ho15hauhj7hhdblkltrll9tdo9rk0ln@4ax.com...
> Ewoud Dronkert wrote:
>> And, is there only one index value for each personid??
>
> One salary figure, I mean. It do seems likely to have only one salary per
> person, also the sorting wouldn't make sense otherwise.
>
> A far better data structure would probably be, in pseudo code:
> $person[] = array('id' => (int), 'name' => (string), 'salary' => (float));
>
> Then the solution would be:
>
> function cmp($a, $b) {
> return $a['salary'] - $b['salary'];
> }
>
> Or a little safer:
>
> function cmp($a, $b) {
> $e = 0.01;
> $t = $a['salary'] - $b['salary'];
> if ( $t >= $e ) return 1;
> if ( $t <= -$e ) return -1;
> return 0;
> }
>
> Followed by:
>
> usort($person, 'cmp');
> foreach ( $person as $p )
> printf('%3d %-20s %8.2f', $p['id'], $p['name'], $p['salary']);
>
> --
> E. Dronkert
Navigation:
[Reply to this message]
|