나는 2 배열을 가지고 출력 배열을 만들고 싶습니다.배열을 비교 PHP foreach 루프
제목과 자막 필드예 배열 요구 사항 :
Array
(
[title] => Array
(
[required] => 1
[minLength] => 2
[maxLength] => 50
)
[subtitle] => Array
(
[required] => 1
[minLength] => 2
[maxLength] => 55
)
)
포스트 포스트의 후 배열 :
Array
(
[title] =>
[subtitle] => s
)
예 출력 배열 :
Array
(
[title] => Array
(
[0] => this field is required
[1] => must be longer than 2
)
[subtitle] => Array
(
[0] => must be longer than 2
)
)
이 어떻게 생성 할 수 있습니다와 같은 배열 foreach 루프에 의해?
이것은 내가 가지고있는 것이지만 잘 작동하지는 않습니다. 제목을 공백으로 남겨두고 자막 1 문자를 남겨두면이 필드는 2 배 되돌려 야합니다. 그가 복제 한 것 같습니다. 여기
class Forms_FormValidationFields {
private $_required;
private $_minLength;
private $_maxLength;
private $_alphaNumeric;
public $_errors;
public function __construct($validate, $posts) {
array_pop($posts);
$posts = array_slice($posts,1);
foreach ($posts as $postName => $postValue) {
foreach($validate[$postName] as $key => $ruleValue){
$set = 'set'.ucfirst($key);
$get = 'get'.ucfirst($key);
$this->$set($postValue , $ruleValue);
if($this->$get() != '' || $this->$get() != NULL) {
$test[$postName][] .= $this->$get();
}
}
}
$this->_errors = $test;
}
public function setValidation(){
return $this->_errors;
}
public function getRequired() {
return $this->_required;
}
public function setRequired($value, $ruleValue) {
if (empty($value) && $ruleValue == TRUE) {
$this->_required = 'this field is required';
}
}
public function getMinLength() {
return $this->_minLength;
}
public function setMinLength($value, $ruleValue) {
if (strlen($value) < $ruleValue) {
$this->_minLength = ' must be longer than' . $ruleValue . '';
}
}
public function getMaxLength() {
return $this->_maxLength;
}
public function setMaxLength($value, $ruleValue) {
if (strlen($value) > $ruleValue) {
$this->_maxLength = 'must be shorter than' . $ruleValue . '';
}
}
}
지금까지 있나요? 어디에서 차단 되었습니까? – Lepidosteus
위의 Lepidosteus 참조. – Bas