How to write to the first element of an array?
I know reset can return the first element… but you can not use it to write to it.
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.
Anything wrong with
$yourarray[0] = $value?If you don’t want to overwrite the first element, try “array_unshift”:
http://www.php.net/manual/en/function.array-unshift.php
EDIT:
ok, use this for non-numerical keys: