Re: Finding next recored in a array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rick Pasotto wrote:
On Sun, Sep 16, 2007 at 06:04:45PM -0700, Richard Kurth wrote:
Richard Kurth wrote:
Rick Pasotto wrote:
On Sun, Sep 16, 2007 at 07:09:02PM -0400, 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.
Nope. Just use array_search().

$k = array_search('5',$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

I tried this and it gives me nothing back. It should give me a 8

$Campaign_array= array('0','1','3','5','8','15','25');
$val="5";

$k = array_search($val,$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

I figured out way it was not working $k + 1 > count needed to be $k + 1 < count

Yup. Sorry 'bout that.

But now it works perfect


if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

is very over-the-top. What's wrong with
if (isset($Campaign_array[$k+1]) { echo $Campaign_array[$k + 1]; }

Not to mention I don't really like the whole way this has been handled, I'm sure there are better ways, but for this we'd need to know more about what you're doing and what you're trying to achieve, which we obviously don't.

- Tul

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux