Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

CodeWall:
5 Ways To Loop Through An Array In PHP
Sep 25, 2018 @ 16:04:25

On the CodeWall site Dan Englishby walks you through some of the basic functionality in the PHP language for working with arrays. In it he shows how to loop through an array using multiple tools including the usual control structures and others less widely used.

PHP, just like most other programming languages has multiple ways to loop through arrays. The most popular ways to do it usually is with a while, for and foreach operator, but, believe it or not, there more ways to do it with PHP. In this article I will walk-through each possibility for reading arrays whilst looping.

He breaks the article up into sections, one for each of the methods:

  • the white loop
  • the for loop
  • the foreach loop
  • the do/while loop
  • using the ArrayIterator

Each item in the list comes with a summary of how it works and some code showing it in action.

tagged: introduction tutorial language loop array top5 example

Link: https://www.codewall.co.uk/5-ways-to-loop-through-array-php/


Trending Topics: