[PHP-WIN] Re: Array question

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

 



hi again jocke... seems i'll give a go at answering your questions again ;-)

If I understand your question properly, I doubt the previous poster's
response would be useful to you.

The bad news (I think): there are limited functions that deal with array
pointers. There are plenty to deal with arrays themselves.

as you've noted: pos, next, prev seem to be the only way to deal with a
pointer, so yes, the way that I implemented my solution was to use next and
pos to get the positioning and in doing so, reading the *entire array*
(yuck) and storing into a new array based on conditions.

option 1) I haven't tried, so I'm not sure if array_search (for key) and
in_array (for value) move the pointer - maybe you could try those. (gut feel
is they don't). If they do, then you can for loop a prev/next to get what
you want.

option 2) I guess you could actually use integers as your index and have
them sort-ed (or array_push them on) that might solve your problem, but I
think that's a bit of a kludge. (ie, implicitly using the array key value as
a pointer)

option 3) So.... the only way I found was to loop thru the whole array, it's
messy for large sets, but if your array size is only 100 (I doubt it is) it
may be ok. It seems excessive though.

looping thru the entire set might not be too bad, I assume that's what an
array_search might be doing as well(?) so you're not saving any more time
even if that works.

Anyhow, tell me if you find another method... i'll go off and do more
research on it now too.

"Disko_kex" <disko_kex@swedish-mushroom.com> wrote in message
006301c36ad6$5cc81d30$e900a8c0@lokalguirdcfee">news:006301c36ad6$5cc81d30$e900a8c0@lokalguirdcfee...
> If I have an array like this > [0] => 1 [1] => 2 [2] => 3 ... [99] =>
> 100
>
> If I want to select [50] => 51 and store the value that's 2 positions
> before and 1 position after, how can I do?
>
> If I want to know what position value 71 have?
>
>
> I have search the PHP-manual and found some functions as prev, next, pos
> etc. But with these commands I have to loop thru the array every time to
> reach the the values and positions. It has to be an easier way to do it.
>
> // jocke
>

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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux