Is there a way to only keep the first N (for example 10) elements of an array? I know there is array_pop, but is there a better, more elegant way?
Is there a way to only keep the first N (for example 10) elements
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.
You can use
array_sliceorarray_splice:Note that
array_slicecopies the items of$aand returns them whilearray_splicedoes modify$aitself and only returns the items that have been removed from$a.