<?php
class Form {
public $data = [];
public $fields;
function __construct($fields) {
$this->fields = $fields;
foreach($this->fields as &$field) {
$this->data[$field['id']] = &$field['value'];
}
}
}
$f = new Form([
[
'id' => 'fname',
'value' => 'George'
],
[
'id' => 'lname',
'value' => 'Lucas'
]
]);
echo $f->data['fname'], $f->fields[0]['value'];
$f->data['fname'] = 'Ralph';
echo $f->data['fname'], $f->fields[0]['value'];
PD9waHAKCmNsYXNzIEZvcm0gewoJcHVibGljICRkYXRhID0gW107CglwdWJsaWMgJGZpZWxkczsKCQoJZnVuY3Rpb24gX19jb25zdHJ1Y3QoJGZpZWxkcykgewoJCSR0aGlzLT5maWVsZHMgPSAkZmllbGRzOwoJCWZvcmVhY2goJHRoaXMtPmZpZWxkcyBhcyAmJGZpZWxkKSB7CgkJCSR0aGlzLT5kYXRhWyRmaWVsZFsnaWQnXV0gPSAmJGZpZWxkWyd2YWx1ZSddOwoJCX0KCX0KfQoKJGYgPSBuZXcgRm9ybShbCglbCgkJJ2lkJyA9PiAnZm5hbWUnLAoJCSd2YWx1ZScgPT4gJ0dlb3JnZScKCV0sCglbCgkJJ2lkJyA9PiAnbG5hbWUnLAoJCSd2YWx1ZScgPT4gJ0x1Y2FzJwoJXQpdKTsKCmVjaG8gJGYtPmRhdGFbJ2ZuYW1lJ10sICRmLT5maWVsZHNbMF1bJ3ZhbHVlJ107CiRmLT5kYXRhWydmbmFtZSddID0gJ1JhbHBoJzsKZWNobyAkZi0+ZGF0YVsnZm5hbWUnXSwgJGYtPmZpZWxkc1swXVsndmFsdWUnXTs=