Skip to content

Instantly share code, notes, and snippets.

@tiffany-taylor
Created January 13, 2021 04:33
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 tiffany-taylor/0a3c8fe9ed5db0a3bb93a06d39895fe9 to your computer and use it in GitHub Desktop.
Save tiffany-taylor/0a3c8fe9ed5db0a3bb93a06d39895fe9 to your computer and use it in GitHub Desktop.
<?php
function do_a_thing(string $firstVar, string $secondVar){}
$items = [
'mouse' => 'some arbitrary value',
'keyboard' => 'some arbitrary value',
'monitor' => 'some arbitrary value',
'microphone' => 'some arbitrary value',
'headset' => 'some arbitrary value',
'PC' => 'some arbitrary value',
'webcam' => 'some arbitrary value',
'desk' => 'some arbitrary value',
'pen' => 'some arbitrary value',
'post-it' => 'some arbitrary value',
];
$limitValues = ['mouse', 'keyboard', 'monitor', 'microphone', 'headset'];
foreach ($items as $key => $value) {
if (array_keys($limitValues, $key)) {
do_a_thing($key, $value);
}
}
<?php
function do_a_thing(string $firstVar, string $secondVar){}
$items = [
'mouse' => 'some arbitrary value',
'keyboard' => 'some arbitrary value',
'monitor' => 'some arbitrary value',
'microphone' => 'some arbitrary value',
'headset' => 'some arbitrary value',
'PC' => 'some arbitrary value',
'webcam' => 'some arbitrary value',
'desk' => 'some arbitrary value',
'pen' => 'some arbitrary value',
'post-it' => 'some arbitrary value',
];
foreach ($items as $key => $value) {
switch ($key) {
case 'mouse':
case 'keyboard':
case 'monitor':
case 'microphone':
case 'headset':
do_a_thing($key, $value);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment