Skip to content

Instantly share code, notes, and snippets.

@am-
Last active October 28, 2016 07:15
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 am-/427f3ccf77bc542526538d91f953e1b0 to your computer and use it in GitHub Desktop.
Save am-/427f3ccf77bc542526538d91f953e1b0 to your computer and use it in GitHub Desktop.
<?php
function computationWithAssumedKeys(array $array, array $necessaryKeys) {
$missingKeys = array_diff($necessaryKeys, array_keys($array));
if (!empty($missingKeys)) {
$message = 'Computation failed due to missing key(s): ' . implode(', ', $missingKeys);
throw new \RuntimeException($message);
}
// compute...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment