Friday, 15 February 2013

php - Getting last 6 values from an multidimensional array -


I need to get the last 6 values ​​from a multi-dimensional array, I was trying to do something like this

{$ stats = array_shift ($ stats); }

But then after the first array_shift, I receive the following error

  PHP Warning: array_shift (): Argument must be an array  < / Pre> 

Is there any work that can be done in PHP?

You can use:

$ stats = array_slice ( $ Figures, -6);

The reason for this is that your code is not working because

  1. draws from the front of the array - so that you remove the first 6, which The last 6 is not the same as receiving, as long as your array does not have 12 items ...
  2. The array_shift edits the array in place and removes the item

No comments:

Post a Comment