Skip to content

Instantly share code, notes, and snippets.

@simonhamp simonhamp/list.php
Last active Mar 11, 2020

Embed
What would you like to do?
Using list() in foreach in PHP
<?php
$items = [
['field' => 'field1', 'values' => [0, 1, 2, 3, 4]],
['field' => 'field2', 'values' => ['cat', 'dog', 'horse']]
];
foreach ($items as list('field' => $field, 'values' => $values)) {
// can use $field and $values here now!
}
@simonhamp

This comment has been minimized.

Copy link
Owner Author

simonhamp commented Jan 8, 2018

This is taken from a comment I posted on this article by Josh Sherman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.