Last active
December 11, 2015 08:59
-
-
Save oaass/4577325 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$required = array('hostname', 'username', 'password', 'database', 'driver'); | |
$config = array( | |
'password' => 'pass', | |
'database' => 'mydb', | |
'charset' => 'utf8', | |
'port' => '1234' | |
); | |
$errors = array_diff($required, array_flip($config)); | |
$last = array_pop($errors); | |
$errmsg = 'Missing required configurations. No %s or %s has been configured'; | |
var_dump(sprintf($errmsg, implode(', ', $errors), $last)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@flavius yeah I agree $last can a "dangerous" variable for this. This was just for showing. It also requires for two elements to be missing as well. But it was just to illustrate that this was simpler than array_map. I wasn't actually able to make array_map work in this situation, which was why I looked elsewhere for a solution.