Jump to content

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 ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.