unemployment Posted June 9, 2011 Share Posted June 9, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/ Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/#findComment-1227609 Share on other sites More sharing options...
KevinM1 Posted June 9, 2011 Share Posted June 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/#findComment-1227621 Share on other sites More sharing options...
Maq Posted June 9, 2011 Share Posted June 9, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/#findComment-1227625 Share on other sites More sharing options...
KevinM1 Posted June 9, 2011 Share Posted June 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/#findComment-1227631 Share on other sites More sharing options...
unemployment Posted June 9, 2011 Author Share Posted June 9, 2011 I used fugix example and I am thrilled to have this work. I just made Ajax pagination for my news feed Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/#findComment-1227633 Share on other sites More sharing options...
Maq Posted June 9, 2011 Share Posted June 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/#findComment-1227643 Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 I used fugix example and I am thrilled to have this work. I just made Ajax pagination for my news feed glad you got it to work, lol at Maq Quote Link to comment https://forums.phpfreaks.com/topic/238905-get-the-last-value-in-a-for-loop/#findComment-1227644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.