Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 856
  • Last Modified:

PHP shorten array

I haven't found an array function yet that will shorten an array to the specified number of elements.  Anyone know what would help here, please?  Also, looking for a function to remove the first x number of elements from the beginning of an array.

Thanks!
0
earthman100
Asked:
earthman100
1 Solution
 
_Marcel_Commented:
I think you are looking for array_slice() ( http://www.php.net/manual/en/function.array-slice.php ) To shorten an array to the first 24 elements use the following:

$output = array_slice($input, 0, 24);

or for the last 24:

$output = array_slice($input, -24);

Further, array_shift ( http://www.php.net/manual/en/function.array-shift.php ) will remove the first element of an array. Also take a look at array_splice ( http://www.php.net/manual/en/function.array-splice.php ), which gives you the possibility to replace parts of the array.
0
 
earthman100Author Commented:
duh!
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now