// a beautiful multidimensional array
public $form = array (
array(
'field' => 'email',
array(
'params' =>
array(
'rule' => 'email',
'on' => 'create',
'required' => true,
),
),
array(
'params' =>
array(
'rule' => 'email',
'on' => 'update',
'required' => false,
)
)
)
);
// beautiful foreach loops
public function validate($form) {
foreach ($form as $valueA) {
$field = $valueA['field'];
foreach ($valueA as $valueB) {
$params = $valueB['params'];
foreach ($valueB as $valueC) {
$rule = $valueC['on'];
$on = $valueC['on'];
$required = $valueC['required'];
$this->isValid($field, $rule, $on, $required);
}
}
}
}
// they do not work together!!!
// a beautiful multidimensional array public $form = array ( array( ‘field’ => ’email’,
Share
It looks to me like you’re going to generate errors in your second loop:
This is going to include
fieldin the loop and will encounter problems when it tries to access it as an array.Also, I think you mean for your third loop to be:
Otherwise, it runs into the same problems as the middle loop.
I think that, if you intend to keep using this as an array rather than refactor it into a class as others have suggested, you should restructure it so that the named data is all at the same level. Notice that this reduces the complexity of both the array (a little) and the loops (a lot).