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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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