public static function set($data) { $user_profile = \lib\user_profile::get($data['id']); foreach ($data as $key => $value) { if (!isset($user_profile[$key])) { // add it \lib\user_profile::add($data['id'], $key, $value); } else { if ($user_profile[$key] != $value) { // change it \lib\user_profile::update($data['id'], $key, $value); } else { // do nothing } } } }