Forum Moderators: coopster

Message Too Old, No Replies

Testing for first, last position in an array

         

fintan

4:01 pm on Jul 25, 2005 (gmt 0)

10+ Year Member



Hi I'm looking for away to test for the first and last position in an array in a loop. Any ideas?
Thanks

fintan.

jatar_k

4:05 pm on Jul 25, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what do you want to test them for?

fintan

4:12 pm on Jul 25, 2005 (gmt 0)

10+ Year Member



I want to test if the first key equals 0 and the value of the last key. Thanks jatar_k

Anyango

4:36 pm on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$first= yourArray[0];
$last= yourArray[count(yourArray)-1];

if($first==0)
{
//first value of array equals 0
}
if($first==$last)
{
//first value of array equals last value of array
}

Please discard my message if you its not what you are lookin for

fintan

9:20 pm on Jul 25, 2005 (gmt 0)

10+ Year Member



Thanks for the reply I'll take a look at it in the morning

madmac

2:40 am on Jul 26, 2005 (gmt 0)

10+ Year Member



have a look in the PHP manual at the functions:

array_slice()
array_pop()

fintan

3:19 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



Thanks for the responces. Got it with setting a variable to true then false