Example #1
0
/**
 * Recursive Diff
 *
 * @param array $aArray1
 * @param array $aArray2
 * @return diff array
 */
function arrayRecursiveDiff($aArray1, $aArray2)
{
    $aReturn = array();
    foreach ($aArray1 as $mKey => $mValue) {
        if (array_key_exists($mKey, $aArray2)) {
            if (is_array($mValue)) {
                $aRecursiveDiff = arrayRecursiveDiff($mValue, $aArray2[$mKey]);
                if (count($aRecursiveDiff)) {
                    $aReturn[$mKey] = $aRecursiveDiff;
                }
            } else {
                if ($mValue != $aArray2[$mKey]) {
                    $aReturn[$mKey] = $mValue;
                }
            }
        } else {
            $aReturn[$mKey] = $mValue;
        }
    }
    return $aReturn;
}
Example #2
0
 /**
  * Update customer data
  *
  * @param array $update
  * @return bool
  */
 public function update($update = null)
 {
     if (!empty($update) && is_array($update)) {
         unset($update['customer_id']);
         foreach ($update as $k => $v) {
             if (isset($this->_user_data[$k]) && $this->_user_data[$k] != $v) {
                 $this->_user_data[$k] = $v;
                 $this->_changed = true;
             }
         }
         if ($this->_changed) {
             return $this->_update();
         }
     } else {
         if (isset($_POST['update'])) {
             $remove = array_diff_key($_POST, $this->_user_data);
             $update = $_POST;
             //Remove different keys
             foreach ($remove as $k => $v) {
                 unset($update[$k]);
             }
             //Remove things that shouldn't be updated by post
             unset($update['salt']);
             unset($update['customer_id']);
             unset($update['status']);
             unset($update['type']);
             //Check of any acutal changes
             $diff = arrayRecursiveDiff($update, $this->_user_data);
             if (!empty($diff)) {
                 $this->_user_data = array_merge($this->_user_data, $update);
                 $this->_changed = true;
                 return $this->_update();
             }
         }
     }
     return false;
 }