Re: [PHP-DB] php array max value pr. year

2002-11-11 Thread Peter Beckman
First create this array before you do anything:

$max = array(10=>1,
 20=>1,
 40=>1,
 60=>1,
 320=>1,
 780=>1,
 890=>1,
 920=>1);

$year[2002] = $max;
$year[2003] = $max;

$i = 0;
while(list($a,$b)=each($v)) {
$year[$y[$i]][$v[$i]] = 0;
}

reset($year);
while(list($a,$b)=each($year)) {
while(list($c,$d)=each($b)) {
if ($d == 1) $next[$a][$c]=1;
}
}

At this point $next will be a two dimensional array IF all the V's in a
year are not used up.  If they are, $next[2002] for example will be
!isset($next[2002]).

To get your $Y and $V:

reset($next);
while(list($a,$b)=each($next)) {
$leftoveryears[] = $a;
while(list($c,$d)=each($b)) {
$leftovervalues[] = $c;
}
}

Now $leftoveryears is an array of years and $leftovervalues is an array of
values.

I would highly recommend using a single multi-dimensional array instead of
blind indexing for your year to value pairs.  IE:

$pairs[2002][10] = 1; // (if set)

Peter




On Mon, 11 Nov 2002, Martin Allan Jensen wrote:

> Hi evryonei have a problem that i hope you can help me with.
>
> Here it goes!
>
> I have two arrays one called "y" adn one called "v"
> Togeather they hold a year(Y) and a value(V)
>
> The array looks like this:
>
> v:
> 10
> 20
> 40
> 60
> 320
> 780
> 890
> 920
>
> y:
> 2002
> 2002
> 2002
> 2002
> 2002
> 2003
> 2003
> 2003
>
> -
>
> V represents a climping value
> Y represents the year of the value
> 
>
> So  the values 10, 20, 40, 60, 320 etc. grows until a new year is reachet. And then 
>it schould start again in the new year.
> So MAXIMUM ONE VALUE PER YEAR
>
> How can i make it return this out of the earlier menchent array :
>
> (Arrays)
> Y:
> 2002
> 2003
>
> V:
> 320
> 920
>
> So much thanks peoplei tried now for two days and i just can't come up with 
>anything...
>
> P.S. Sorry for my bad english!
>
> Martin Allan Jensen
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

---
Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation
[EMAIL PROTECTED] http://www.purplecow.com/
---


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] php array max value pr. year

2002-11-11 Thread Ignatius Reilly
Hi Martin,

I am sure that many would love to help you, but really you must explain your
problem more clearly! Can you give more details?

Ignatius

- Original Message -
From: "Martin Allan Jensen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, November 11, 2002 10:24 AM
Subject: [PHP-DB] php array max value pr. year


Hi evryonei have a problem that i hope you can help me with.

Here it goes!

I have two arrays one called "y" adn one called "v"
Togeather they hold a year(Y) and a value(V)

The array looks like this:

v:
10
20
40
60
320
780
890
920

y:
2002
2002
2002
2002
2002
2003
2003
2003

-

V represents a climping value
Y represents the year of the value


So  the values 10, 20, 40, 60, 320 etc. grows until a new year is reachet.
And then it schould start again in the new year.
So MAXIMUM ONE VALUE PER YEAR

How can i make it return this out of the earlier menchent array :

(Arrays)
Y:
2002
2003

V:
320
920

So much thanks peoplei tried now for two days and i just can't come up
with anything...

P.S. Sorry for my bad english!

Martin Allan Jensen


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] php array max value pr. year

2002-11-11 Thread Jason Wong
On Monday 11 November 2002 17:24, Martin Allan Jensen wrote:
> Hi evryonei have a problem that i hope you can help me with.
>
> Here it goes!
>
> I have two arrays one called "y" adn one called "v"
> Togeather they hold a year(Y) and a value(V)
>
> The array looks like this:

Can I ask, how you did get these arrays? Did you define these or did come from 
somewhere else?  And why are they in two separate arrays? ...

> v:
> 10
> 20
> 40
> 60
> 320
> 780
> 890
> 920
>
> y:
> 2002
> 2002
> 2002
> 2002
> 2002
> 2003
> 2003
> 2003
>
> -

... In most cases you're better off using a single array to hold both pieces 
of information.

> V represents a climping value
> Y represents the year of the value
> 
>
> So  the values 10, 20, 40, 60, 320 etc. grows until a new year is reachet.
> And then it schould start again in the new year. So MAXIMUM ONE VALUE PER
> YEAR

Right, do you actually do anything with the non-maximum values? Are they used 
anywhere in your code, or do you really just want the maximum value for each 
year?

> How can i make it return this out of the earlier menchent array :
>
> (Arrays)
> Y:
> 2002
> 2003
>
> V:
> 320
> 920

There may be an easy way to solve your problem, but first you need to:

1) explain why you're using 2 arrays
2) state whether the non-maximum values are used at all, if they are being 
used, /how/ are they being used.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
You have literary talent that you should take pains to develop.
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] php array max value pr. year

2002-11-11 Thread Martin Allan Jensen
Hi evryonei have a problem that i hope you can help me with.

Here it goes!

I have two arrays one called "y" adn one called "v" 
Togeather they hold a year(Y) and a value(V)

The array looks like this:

v:
10
20
40
60
320
780
890
920

y:
2002
2002
2002
2002
2002
2003
2003
2003

-

V represents a climping value
Y represents the year of the value


So  the values 10, 20, 40, 60, 320 etc. grows until a new year is reachet. And then it 
schould start again in the new year.
So MAXIMUM ONE VALUE PER YEAR

How can i make it return this out of the earlier menchent array :

(Arrays)
Y:
2002
2003

V:
320
920

So much thanks peoplei tried now for two days and i just can't come up with 
anything...

P.S. Sorry for my bad english!

Martin Allan Jensen


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php