fork(1) download
  1. <?php
  2.  
  3. $data = array("attr1", "attr2", "attr3", "attr4", "attr5");
  4. $required = array("attr2", "attr5");
  5. $data2 = array("attr1", "attr3", "attr4", "attr5");
  6.  
  7. function validate_required ($data, $required) {
  8. $c = 2;
  9.  
  10. $inBoth = array_intersect($data, $required);
  11. if (count($inBoth) !== $c) {
  12. throw new \Exception('O elemento {elemento} não possui todos os atributos obrigatórios');
  13. }
  14. return true;
  15. }
  16.  
  17. var_dump(validate_required($data, $required));
  18. var_dump(validate_required($data2, $required));
  19.  
Runtime error #stdin #stdout #stderr 0.02s 23828KB
stdin
Standard input is empty
stdout
bool(true)
stderr
PHP Fatal error:  Uncaught Exception: O elemento {elemento} não possui todos os atributos obrigatórios in /home/od6QuE/prog.php:12
Stack trace:
#0 /home/od6QuE/prog.php(18): validate_required(Array, Array)
#1 {main}
  thrown in /home/od6QuE/prog.php on line 12