Does foreach() work for non-numerical array keys?

后端 未结 3 1052
春和景丽
春和景丽 2021-01-29 12:03

I was wondering if foreach() works when the array looks like this:

  • arr_name[eggs] = something
  • arr_name[pencil] = something else

Will foreac

3条回答
  •  醉话见心
    2021-01-29 12:21

    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.

提交回复
热议问题