fork download
  1. <?php
  2.  
  3. class Form {
  4. public $data = [];
  5. public $fields;
  6.  
  7. function __construct($fields) {
  8. $this->fields = $fields;
  9. foreach($this->fields as &$field) {
  10. $this->data[$field['id']] = &$field['value'];
  11. }
  12. }
  13. }
  14.  
  15. $f = new Form([
  16. [
  17. 'id' => 'fname',
  18. 'value' => 'George'
  19. ],
  20. [
  21. 'id' => 'lname',
  22. 'value' => 'Lucas'
  23. ]
  24. ]);
  25.  
  26. echo $f->data['fname'], $f->fields[0]['value'];
  27. $f->data['fname'] = 'Ralph';
  28. echo $f->data['fname'], $f->fields[0]['value'];
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
GeorgeGeorgeRalphRalph