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); Quote Link to comment Share on other sites More sharing options...
waynew Posted July 11, 2008 Author Share Posted July 11, 2008 Anyone? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.