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

Michelangelo van Dam:
PHP Arrays - The php array functions
Feb 08, 2016 @ 11:51:02

Michelangelo Van Dam is back with another part of his series covering the use of arrays in PHP. In previous articles he covered some of the basics including operations and associative arrays but in this new post he moves up and talks about some of the other functions you can use to manipulate them even further.

In my previous article about arrays (the basics, simple operations and associative arrays or hash maps) I have shown what arrays are and what you can do with it. Now I want to dive into real fun and explain PHP's array functions with real-world examples and how you can apply them in your day-to-day work.

He then goes through several of the PHP array functions, providing simple code snippets of them in action. To help apply it to a more "real world" situation he uses data based on a "countries" table in a database, making use of the "iso" and "printable_name" columns:

This is only three of the many methods you can use in PHP to manipulate arrays but it gives you a taste of what's there and what's to come in his future articles.

tagged: array tutorial functions arraywalk arraymap arrayintersectkey

Link: http://www.dragonbe.com/2016/02/php-arrays-php-array-functions.html

Developer Tutorials Blog:
PHP array_walk(): Run an array through a function
Apr 23, 2008 @ 08:47:09

The Developer Tutorials blog has a quick example of how to use the array_walk function to maneuver through the array of your choosing and applying a callback method to each of its elements.

It’s a common sight: taking an array and running (well, walking) its elements through a particular function. Luckily, PHP provides a simple yet powerful function to overcome this: array_walk().

They include an example, giving a sample "some_function" the array_walk method uses when it's called, replacing a foreach (or other type of loop). Plus you can specify an object with the callback to run it against a method inside a class too.

tagged: arraywalk function callback object method loop tutorial