I was wondering if foreach() works when the array looks like this:
- arr_name[eggs] = something
- arr_name[pencil] = something else
Will foreach work if run as:
foreach(arr_name as $key => $value)
for they keys that have a non-numerical value ?
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.
Yes,
foreachsupports any kind of key. In your case,$keywill be a string,'eggs'and'pencil'respectively for each item. In fact,foreachwas intended for use with arrays that have non-numerical keys which you can’t easily iterate usingfor.