<?php
$data = array ( "attr1" , "attr2" , "attr3" , "attr4" , "attr5" ) ; $required = array ( "attr2" , "attr5" ) ; $data2 = array ( "attr1" , "attr3" , "attr4" , "attr5" ) ;
function validate_required ( $data , $required ) {
$c = 2 ;
if ( count ( $inBoth ) !== $c ) { throw new \Exception( 'O elemento {elemento} não possui todos os atributos obrigatórios' ) ;
}
return true ;
}
var_dump ( validate_required
( $data , $required ) ) ; var_dump ( validate_required
( $data2 , $required ) ) ;
PD9waHAKCiRkYXRhID0gYXJyYXkoImF0dHIxIiwgImF0dHIyIiwgImF0dHIzIiwgImF0dHI0IiwgImF0dHI1Iik7CiRyZXF1aXJlZCA9IGFycmF5KCJhdHRyMiIsICJhdHRyNSIpOwokZGF0YTIgPSBhcnJheSgiYXR0cjEiLCAiYXR0cjMiLCAiYXR0cjQiLCAiYXR0cjUiKTsKCmZ1bmN0aW9uIHZhbGlkYXRlX3JlcXVpcmVkICgkZGF0YSwgJHJlcXVpcmVkKSB7CiAgICAkYyA9IDI7CgogICAgJGluQm90aCA9IGFycmF5X2ludGVyc2VjdCgkZGF0YSwgJHJlcXVpcmVkKTsKICAgIGlmIChjb3VudCgkaW5Cb3RoKSAhPT0gJGMpIHsKICAgICAgICB0aHJvdyBuZXcgXEV4Y2VwdGlvbignTyBlbGVtZW50byB7ZWxlbWVudG99IG7Do28gcG9zc3VpIHRvZG9zIG9zIGF0cmlidXRvcyBvYnJpZ2F0w7NyaW9zJyk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKfQoKdmFyX2R1bXAodmFsaWRhdGVfcmVxdWlyZWQoJGRhdGEsICRyZXF1aXJlZCkpOwp2YXJfZHVtcCh2YWxpZGF0ZV9yZXF1aXJlZCgkZGF0YTIsICRyZXF1aXJlZCkpOwo=