fork download
  1. <?php
  2.  
  3. $li = new stdClass;
  4. $li->company = "Company";
  5. $li->last = "Last";
  6.  
  7. $insert = array();
  8. foreach (['company', 'first', 'last'] as $field) {
  9. $insert[$field] = isset($li->{$field}) ? $li->{$field} : "";
  10. }
  11.  
  12. var_dump($insert);
Success #stdin #stdout 0.02s 23720KB
stdin
Standard input is empty
stdout
array(3) {
  ["company"]=>
  string(7) "Company"
  ["first"]=>
  string(0) ""
  ["last"]=>
  string(4) "Last"
}