Jump to content

[SOLVED] Array problem.


waynew

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

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