Difference between “as $key => $value” and “as $value” in PHP foreach

前端 未结 8 2220
梦毁少年i
梦毁少年i 2021-01-30 01:21

I have a database call and I\'m trying to figure out what the $key => $value does in a foreach loop.

The reason I ask is because both these

8条回答
  •  渐次进展
    2021-01-30 02:08

    if the array looks like:

    • $featured["fruit"] = "orange";
    • $featured["fruit"] = "banana";
    • $featured["vegetable"] = "carrot";

    the $key will hold the type (fruit or vegetable) for each array value (orange, banana or carrot)

提交回复
热议问题