Afficher un message
Vieux 17/09/2007, 00h35   #3
Richard Kurth
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Finding next recored in a array

brian wrote:
> Richard Kurth wrote:
>> $Campaign_array| = array('0','1','3','5','8','15','25');|
>> I know that I can find the next recored in a array using next. What I
>> do not understand is if I know the last number was say 5 how do I
>> tell the script that that is the current number so I can select the
>> next record
>> ||
>>

>
> I think you'll need your own function for this. Pass in the array and
> loop through it until you find the key, increment that, ensure that
> there is another value with that key, and return the key (or the value).
>
> (untested)
>
> function nextInArray($arr, $val)
> {
> $next_key = NULL;
>
> for ($i = 0; $i < sizeof($arr);$i++)
> {
> if ($arr[$i] == $val)
> {
> $next_key = ++$i;
> break;
> }
> }
>
> // return the key:
> return (array_key_exists($next_key) ? $next_key : NULL);
>
> // or the value:
> return (array_key_exists($next_key) ? $arr[$next_key] : NULL);
>
> }
>
> However, in your example, you're searching for the key that points to
> the value '5'. What if the value '5' occurs more than once?
>
> brian
>

In my script the value of 5 will not reoccur the numbers are number of
days from 0 up to 30 days.

Thanks for the function
  Réponse avec citation
 
Page generated in 0,05565 seconds with 9 queries