As we know, there are four functions that can be used to insert into and delete from an array:
- array_push()
- array_pop()
- array_unshift()
- array_shift()
What’s the meaning of array_unshift() and array_shift(), I mean why they are named like this?
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.
It’s historical. Whereas in newer languages we probably wouldn’t call it “shift” any more, older terminology from Perl includes the shift keyword, whose job is to:
This is often used with the
@_array, which contains function arguments, andshiftwould provide access to them one at a time.PHP, in its early days when Perl was still widely used for web programming, has simply taken this terminology, added the “inverse”
unshiftand left it.Another example is
glob, which is named after the libcglob()function. I imagine the intent was to make these functions familiar to those coming to PHP from existing languages, but in retrospect a decade or so later, perhaps the terms have aged poorly.