How to get PHP foreach loop key value?

Spread the love

Sometimes, we want to get PHP foreach loop key value.

In this article, we’ll look at how to get PHP foreach loop key value.

How to get PHP foreach loop key value?

To get PHP foreach loop key value, we can get it from the loop header.

For instance, we write

foreach ($array as $key => $value) {
    //...
}

to loop through the $array associative array with a foreach loop.

Then we get the key of each entry from $key.

Conclusion

To get PHP foreach loop key value, we can get it from the loop header.

Leave a Reply

Your email address will not be published.