How to print array key and value in PHP

Often we use arrays but most of the time we forget about the keys in an Array().

If you are the programmer who uses only for() loop function then you are going to learn one more loop function called foreach(). When I first start learning PHP I used to loop through array() only with for() loop, but you know after I start using foreach() I almost forgot using the other loop methods.

So, basically if you want to print out both keys and values you better use foreach() function over for() loop function.

This example shows how to echo both the keys and values from an Array();

I hope this would have helped you, keep learning and keep doing programming. Enjoy!

Related Posts

Leave a Reply