Jump to content

Get the last value in a for loop?


unemployment

Recommended Posts

I need to get the last approved date value of my for loop.  I'm not sure how to do this.  I then need to set this last approved date value as a variable in a link href.

 

for(var i = 0; i < feed[0].length; i++)
{
t = value of the last approved date	
}

more_btn.href = '../home.php?feed=' + feed + '&uid=' + uid + '&t' + t;

Link to comment
https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/
Share on other sites

im thinking that you can use an if statement to check the value of i in comparison to feed[0].length e.g

for(var i = 0; i < feed[0].length; i++)
{
if(i == feed[0].length-1) //finds the last value of i
        {
        // do stuff
        }
}

more_btn.href = '../home.php?feed=' + feed + '&uid=' + uid + '&t' + t;

You don't need to use a loop.  Just access the element at feed[0][feed[0].length-1], if your feed[0] is actually an array itself.

I think you have to use count.

feed[0][count(feed[0])-1]

 

JavaScript, not PHP. ;)

Ooops haha, I thought you made a silly c# mistake ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.