Skip to content

Instantly share code, notes, and snippets.

@simonhamp
Last active June 15, 2021 21:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simonhamp/4ecf63d7ac2f4e16dd427ee6ec51d024 to your computer and use it in GitHub Desktop.
Save simonhamp/4ecf63d7ac2f4e16dd427ee6ec51d024 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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