I was wondering if foreach() works when the array looks like this:
Will foreac
Yes, foreach supports any kind of key. In your case, $key will be a string, 'eggs' and 'pencil' respectively for each item. In fact, foreach was intended for use with arrays that have non-numerical keys which you can't easily iterate using for.
foreach
$key
'eggs'
'pencil'
for