Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-21-2009, 07:46 AM
  #1
DamianWarS
Champion (Level 13)
 
DamianWarS's Avatar
 
Join Date: Jan 2007
Posts: 236
iTrader: (0)
DamianWarS is an unknown quantity at this point
how to know if an array is on the last positon

I have an array with string values as indices. I want to be able to loop through the array until it has reached the last index but I want to control when it goes to the next position and I don't want the loop to control it. So I want to use a while loop to check if the array has reached the last position or not. If it hasn't reached the last position I want it to continue the loop otherwise it ends the loop. I don't want to use a foreach loop or array_walk because I want to control the position of the array. Is there a way to check if the array's position is at the end? here is some pseudo code of what I want to accomplish:

PHP Code:
while (is array's position at the end?){
  if(condition) {
    next($array)
  }

DamianWarS is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-21-2009, 10:51 AM
  #2
DamianWarS
Champion (Level 13)
 
DamianWarS's Avatar
 
Join Date: Jan 2007
Posts: 236
iTrader: (0)
DamianWarS is an unknown quantity at this point
im using current(array) as my check to see if the array has past the last postion or not. here is an example:
PHP Code:
$a = array("index1"=>32"index2"=>30"index3"=>34);
while(
current($a)){ 
    echo 
key($a) . " = " current($a) . "<br />"
    
next($a);

the output should be:
Code:
index1 = 32
index2 = 30
index3 = 34
the php manual for current says:
Quote:
If the internal pointer points beyond the end of the elements list or the array is empty, current() returns FALSE
which works pretty well for what I want.
DamianWarS is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-21-2009, 11:17 AM
  #3
Vege
master of bloody obvious
 
Vege's Avatar
 
Join Date: Sep 2004
Location: Finland
Posts: 3,550
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really niceVege is just really nice
why do you want to do this?
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-21-2009, 03:01 PM
  #4
DamianWarS
Champion (Level 13)
 
DamianWarS's Avatar
 
Join Date: Jan 2007
Posts: 236
iTrader: (0)
DamianWarS is an unknown quantity at this point
it doesn't matter i already answered it
DamianWarS is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart



 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 02:34 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.