waynew Posted July 11, 2008 Share Posted July 11, 2008 Hey guys. I have an array of months. The user gives me two values and I want to be able to give back the months between those two values. However, it isn't working out as I would like it to. I am trying to use array_slice() as you can see but I don't think that I am using properly. Whenever I put in 1 and 3 I get only two months. This is something stupid I know but I thought that this would be the perfect excuse to get one of you guys to explain to me the best way to use array_slice() $start_date = $_GET['startdate']; //begin date. $end_date = $_GET['enddate']; //end date. $end_date = $end_date - $start_date; //Start date and end dates are not really dates. They are index keys. //If there are three months and the user wants to see only the last two months //the start date will be 1 and the end date will be 2. indexes begin at 0 //Split up together in order to maintain sync of timeline and sum. $x_months = array_slice($x_months,$start_date,$end_date); //x months is list of dates. $monthly_profit = array_slice($monthly_profit,$start_date,$end_date); Link to comment https://forums.phpfreaks.com/topic/114270-solved-array-problem/ Share on other sites More sharing options...
waynew Posted July 11, 2008 Author Share Posted July 11, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/114270-solved-array-problem/#findComment-587578 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2008 Share Posted July 11, 2008 Can you show us an example of your data? Ken Link to comment https://forums.phpfreaks.com/topic/114270-solved-array-problem/#findComment-587615 Share on other sites More sharing options...
waynew Posted July 11, 2008 Author Share Posted July 11, 2008 Sorry. I solved it by adding +1 to my indexes during the slice. Thanks anyway Ken. Link to comment https://forums.phpfreaks.com/topic/114270-solved-array-problem/#findComment-587618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.