Skip to content

Instantly share code, notes, and snippets.

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 whoisryosuke/61c585ffe1f465388646193eb244f040 to your computer and use it in GitHub Desktop.
Save whoisryosuke/61c585ffe1f465388646193eb244f040 to your computer and use it in GitHub Desktop.
Specify the variables for specific keys in arrays in PHP7 -- found via: https://blog.frankdejonge.nl/array-destructuring-in-php/
<?php
$members = [
['id' => 1, 'name'=> 'Seb', 'twitter' => '@sebdedeyne' ],
['id' => 2, 'name'=> 'Alex', 'twitter' => '@alexvanderbist'],
['id' => 3, 'name'=> 'Brent', 'twitter' => '@brendt_gd'],
];
foreach ($members as ['twitter' => $twitterHandle, 'name' => $firstName]) {
// do stuff with $twitterHandle and $firstName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment