Combine foreach() with list() PHP 5.5


show more Combining foreach() with list() provides you with in-depth training on Developer. Taught by Jon Peck as part of the PHP 5.5 First Look show less
please wait ...

Combining foreach() with list()

As a developer, one of the common tasks that I see on a regular basis is looping over a result set. Depending on the circumstances, I may need to assign a group of variables to property values or values in an array. Up to this point it's been a manual process, but in PHP 5.5, it's now possible to combine for each with List. This allows me to iterate over the array and unpack nested arrays into looped variables. Using the language construct list as a variable. There is a limitation, I can't use list as a key element, which makes sense.

How am I going to get multiple keys? This sounds neat, in theory, so let's see it in action. If we look at the log, we can see it's pretty straight forward. And it's rendering some kind of log entry that's stored in the database. Let's see what that code looks like. I'm going to go back to the IDE. Then navigate to Classes>Log.php. Take a look at the method toHtml. There's a 4H Loop that goes through...

Combining foreach() with list()
Video duration: 3m 3s 42m 29s Intermediate

Viewers:

Combining foreach() with list() provides you with in-depth training on Developer. Taught by Jon Peck as part of the PHP 5.5 First Look

Subject:
Developer
Software:
PHP
Author:
please wait ...