Skip to content

Instantly share code, notes, and snippets.

@stevenwadejr
Created June 27, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenwadejr/bcb4222dbbed85e1dc581a1b026f2d07 to your computer and use it in GitHub Desktop.
Save stevenwadejr/bcb4222dbbed85e1dc581a1b026f2d07 to your computer and use it in GitHub Desktop.
Using `list()` inside of a `foreach` loop
<?php
$identifiers = [
['contact', 1],
['company', 2],
['contact', 4],
['company', 3]
];
foreach ($identifiers as list($type, $id)) {
echo ucfirst($type) . ' - ' . $id . "\n";
}
?>
Outputs:
Contact - 1
Company - 2
Contact - 4
Company - 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment