note 100789 deleted from function.array-key-exists by crell

From: Date: Wed, 29 Jun 2022 20:42:29 +0000
Subject: note 100789 deleted from function.array-key-exists by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218758@lists.php.net to get a copy of this message
Note Submitter: jens dot hoevenaars at gmail dot com ---- I created this function that uses array key exist to compare a form and a table to see if something has changed. This can be very helpfull if you need to update a table record from a form but you do not want to display all table fields. <?php function($data_from_db, $form_data) { $data = $data_from_db; $keys = array_keys($data); for($i = 0; $i < count($data); $i++) { if(!array_key_exists($keys[$i], $form_data)) { $dbobject->$keys[$i] = $data[$keys[$i]]; } else { $dbobject->$keys[$i] = $form_data[$keys[$i]]; } } return $dbobject; } ?> you can then use the dbobject to update the table.

« previous php.notes (#218758) next »