0

I have an array of key values that looks like this:

array(5) {
  ["2014-04-24"]=>
  int(5)
  ["2014-04-25"]=>
  int(2)
  ["2014-04-27"]=>
  int(1)
  ["2014-04-29"]=>
  int(7)
  ["2014-05-2"]=>
  int(7)
}

Lets say I want to array_slice so that it becomes like this:

array(3) {
  ["2014-04-25"]=>
  int(2)
  ["2014-04-27"]=>
  int(1)
  ["2014-04-29"]=>
  int(7)
}

How do we do this since there is no number indexes?

I have tried the array_slice($theArray, '2014-04-24', '2014-04-29') but that didn't work.

Thanks.

1 Answer 1

2

array_slice expects offset index and length as parameter.

So, what you are looking for is:

array_slice($theArray, 1, 3);

It will return you 3 elements starting from the 1st position (counting starts at zero).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.