What is the best way to accomplish this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use array_slice()
This is an example from the PHP manual: array_slice
There is only a small issue
If the array indices are meaningful to you, remember that
array_slicewill reset and reorder the numeric array indices. You need thepreserve_keysflag set totrueto avoid this. (4th parameter, available since 5.0.2).Example:
Output: