I have an array like:
array(
'username' => array(
'required' => true,
'min' => 5,
'max' => 20,
'unique' => 'users',
'name' => 'Username'
)
);
This array goes into a function like (this is not the complete function):
//$source = $_POST
public function validate($source, $items = array()) {
foreach($items as $item => $rules) {
foreach($rules as $rule => $rule_value) {
//db->sanitize = mysqli_real_escape_string()
$value = $this->db->sanitize($source[$item]);
if($rule === 'required' && empty($value)) {
//The problem is here with $rule['name']
$this->addError($rule['name'].' is empty');
}
}
}
}
So I would like to use the 'name' key from the array to display a user friendly input field name but all it returns is: Warning: Illegal string offset 'name' in
$ruleand$rule_valueare strings. They are the key/value (respectively) of your$rulesarray. I'm guessing you want$rules['name'].