Using List in PHP to Access Array Values to Multi Dimensions

If you are looking to assign the values of an array to a group of variables with one statement, use list(). This construct is used to give a list of variables some value. They work only with arrays that use numeric indexes.


You can also use list to pick individual values while skipping the ones that you do not want.


Multi Dimensional Arrays

As long as the array is an indexed array, you can use lists to access the values of arrays that go multi levels deep. All you have to do is nest the list() construct as well.


Using Each and List Together to Access Arrays

The list() construct is also used together with each() php function to access the values of an array. The each() statement retrieves the key and value of the current array position. We can loop it access all the keys and arrays.


You may also like

Comments are closed here.


Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 2 other subscribers