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; 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; 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. 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] 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. 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 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 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 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
Archived
This topic is now archived and is closed to further replies.