当前位置: 首页>>代码示例>>PHP>>正文


PHP array_compare函数代码示例

本文整理汇总了PHP中array_compare函数的典型用法代码示例。如果您正苦于以下问题:PHP array_compare函数的具体用法?PHP array_compare怎么用?PHP array_compare使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了array_compare函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 /**
  *
  * @param Request $request
  * @param Exercise $exercise
  * @return mixed
  */
 public function update(Request $request, Exercise $exercise)
 {
     // Create an array with the new fields merged
     $data = array_compare($exercise->toArray(), $request->only(['name', 'step_number', 'default_quantity', 'description', 'target', 'priority', 'frequency']));
     $exercise->update($data);
     if ($request->has('stretch')) {
         $exercise->stretch = $request->get('stretch');
         $exercise->save();
     }
     if ($request->has('series_id')) {
         $series = Series::findOrFail($request->get('series_id'));
         $exercise->series()->associate($series);
         $exercise->save();
     }
     if ($request->has('program_id')) {
         $program = ExerciseProgram::findOrFail($request->get('program_id'));
         $exercise->program()->associate($program);
         $exercise->save();
     }
     if ($request->has('default_unit_id')) {
         $unit = Unit::where('for', 'exercise')->findOrFail($request->get('default_unit_id'));
         $exercise->defaultUnit()->associate($unit);
         $exercise->save();
     }
     return $this->responseOkWithTransformer($exercise, new ExerciseTransformer());
 }
开发者ID:JennySwift,项目名称:health-tracker,代码行数:32,代码来源:ExercisesController.php

示例2: update

 /**
  *
  * @param Request $request
  * @param Category $category
  * @return Response
  */
 public function update(Request $request, Category $category)
 {
     // Create an array with the new fields merged
     $data = array_compare($category->toArray(), $request->only(['name']));
     $category->update($data);
     return response($category->transform(), Response::HTTP_OK);
 }
开发者ID:JennySwift,项目名称:lists,代码行数:13,代码来源:CategoriesController.php

示例3: update

 /**
  * UPDATE /api/favouritesTransactions/{favouriteTransactions}
  * @param Request $request
  * @param FavouriteTransaction $favourite
  * @return Response
  */
 public function update(Request $request, FavouriteTransaction $favourite)
 {
     // Create an array with the new fields merged
     $data = array_compare($favourite->toArray(), $request->only(['name', 'type', 'description', 'merchant', 'total']));
     $favourite->update($data);
     if ($request->has('account_id')) {
         $favourite->account()->associate(Account::findOrFail($request->get('account_id')));
         $favourite->fromAccount()->dissociate();
         $favourite->toAccount()->dissociate();
         $favourite->save();
     }
     if ($request->has('from_account_id')) {
         $favourite->fromAccount()->associate(Account::findOrFail($request->get('from_account_id')));
         $favourite->account()->dissociate();
         $favourite->save();
     }
     if ($request->has('to_account_id')) {
         $favourite->toAccount()->associate(Account::findOrFail($request->get('to_account_id')));
         $favourite->account()->dissociate();
         $favourite->save();
     }
     if ($request->has('budget_ids')) {
         $favourite->budgets()->sync($request->get('budget_ids'));
     }
     $favourite = $this->transform($this->createItem($favourite, new FavouriteTransactionTransformer()))['data'];
     return response($favourite, Response::HTTP_OK);
 }
开发者ID:JennySwift,项目名称:budget,代码行数:33,代码来源:FavouriteTransactionsController.php

示例4: update

 /**
  *
  * @param Request $request
  * @param Activity $activity
  * @return Response
  */
 public function update(Request $request, Activity $activity)
 {
     // Create an array with the new fields merged
     $data = array_compare($activity->toArray(), $request->only(['name', 'color']));
     $activity->update($data);
     $activity = $this->transform($this->createItem($activity, new ActivityTransformer()))['data'];
     return response($activity, Response::HTTP_OK);
 }
开发者ID:JennySwift,项目名称:health-tracker,代码行数:14,代码来源:ActivitiesController.php

示例5: update

 /**
  * UPDATE /api/accounts/{accounts}
  * @param UpdateAccountRequest $request
  * @param Account $account
  * @return Response
  */
 public function update(UpdateAccountRequest $request, Account $account)
 {
     // Create an array with the new fields merged
     $data = array_compare($account->toArray(), $request->only(['name']));
     $account->update($data);
     $account = $this->transform($this->createItem($account, new AccountTransformer()))['data'];
     return response($account, Response::HTTP_OK);
 }
开发者ID:JennySwift,项目名称:budget,代码行数:14,代码来源:AccountsController.php

示例6: update

 /**
  * UPDATE /api/weights/{weights}
  * @param Request $request
  * @param Weight $weight
  * @return Response
  */
 public function update(Request $request, Weight $weight)
 {
     // Create an array with the new fields merged
     $data = array_compare($weight->toArray(), $request->only(['weight']));
     $weight->update($data);
     $weight = $this->transform($this->createItem($weight, new WeightTransformer()))['data'];
     return response($weight, Response::HTTP_OK);
 }
开发者ID:JennySwift,项目名称:health-tracker,代码行数:14,代码来源:WeightsController.php

示例7: update

 /**
  *
  * @param Request $request
  * @param Series $series
  * @return mixed
  */
 public function update(Request $request, Series $series)
 {
     // Create an array with the new fields merged
     $data = array_compare($series->toArray(), $request->only(['name', 'priority']));
     //        dd($data);
     $series->update($data);
     if ($request->has('workout_ids')) {
         $series->workouts()->sync($request->get('workout_ids'));
         //            $series->save();
     }
     return $this->responseOkWithTransformer($series, new SeriesTransformer());
 }
开发者ID:JennySwift,项目名称:health-tracker,代码行数:18,代码来源:ExerciseSeriesController.php

示例8: update

 /**
  *
  * @param Request $request
  * @param Timer $timer
  * @return Response
  */
 public function update(Request $request, Timer $timer)
 {
     // Create an array with the new fields merged
     $data = array_compare($timer->toArray(), $request->only(['start', 'finish']));
     $timer->update($data);
     if ($request->has('activity_id')) {
         $timer->activity()->associate(Activity::findOrFail($request->get('activity_id')));
         $timer->save();
     }
     //        dd($timer);
     $finishDate = $this->calculateFinishDate($timer);
     $timer = $this->transform($this->createItem($timer, new TimerTransformer(['date' => $finishDate])))['data'];
     return response($timer, Response::HTTP_OK);
 }
开发者ID:JennySwift,项目名称:health-tracker,代码行数:20,代码来源:TimersController.php

示例9: array_compare

/**
 * Crawl through each array to find differences.
 * 
 * This includes differences in type (i.e. "2", 2 and 2.0 differ) as well as
 * bits present on one side but not on the other.  To catch differences,
 * including those of type, you need to use var_dump() on the result;
 * print_r() is too limited.
 *
 * This version includes dwraven's replacement of isset() with
 * array_key_exists(), as well as a new improvement to allow the comparison of
 * non-array arguments.
 *
 * @param mixed $array1 Array 1 (or anything to test with !==)
 * @param mixed $array2 Array 2
 *
 * @return array An array with two elements, one containing what's in your 
 *               first array, but not your second, and the second is vice 
 *               versa.
 */
function array_compare($array1, $array2)
{
    $diff = false;
    if (!is_array($array1) || !is_array($array2)) {
        // We need two arrays, so return non-array comparison.
        if ($array1 !== $array2) {
            $diff = array($array1, $array2);
        }
        return $diff;
    }
    // Left-to-right
    foreach ($array1 as $key => $value) {
        if (!array_key_exists($key, $array2)) {
            $diff[0][$key] = $value;
        } elseif (is_array($value)) {
            if (!is_array($array2[$key])) {
                $diff[0][$key] = $value;
                $diff[1][$key] = $array2[$key];
            } else {
                $new = array_compare($value, $array2[$key]);
                if ($new !== false) {
                    if (isset($new[0])) {
                        $diff[0][$key] = $new[0];
                    }
                    if (isset($new[1])) {
                        $diff[1][$key] = $new[1];
                    }
                }
            }
        } elseif ($array2[$key] !== $value) {
            $diff[0][$key] = $value;
            $diff[1][$key] = $array2[$key];
        }
    }
    // Right-to-left
    foreach ($array2 as $key => $value) {
        if (!array_key_exists($key, $array1)) {
            $diff[1][$key] = $value;
        }
        // No direct comparsion because matching keys were compared in the
        // left-to-right loop earlier, recursively.
    }
    return $diff;
}
开发者ID:vphantom,项目名称:php-library,代码行数:63,代码来源:array_compare.php

示例10: update

 /**
  * UPDATE /api/foods/{foods}
  * @param Request $request
  * @param Food $food
  * @return Response
  */
 public function update(Request $request, Food $food)
 {
     if ($request->get('updatingCalories')) {
         //We are updating the calories for one of the food's units
         $food->units()->updateExistingPivot($request->get('unit_id'), ['calories' => $request->get('calories')]);
     } else {
         // Create an array with the new fields merged
         $data = array_compare($food->toArray(), $request->only(['name']));
         $food->update($data);
         if ($request->has('default_unit_id')) {
             $food->defaultUnit()->associate(Unit::findOrFail($request->get('default_unit_id')));
             $food->save();
         }
         if ($request->has('unit_ids')) {
             $food->units()->sync($request->get('unit_ids'));
         }
     }
     $food = $this->transform($this->createItem($food, new FoodTransformer()))['data'];
     return response($food, Response::HTTP_OK);
 }
开发者ID:JennySwift,项目名称:health-tracker,代码行数:26,代码来源:FoodsController.php

示例11: array_compare

function array_compare(&$ar1, &$ar2)
{
    if (gettype($ar1) != 'array' || gettype($ar2) != 'array') {
        return FALSE;
    }
    # first a shallow diff
    if (count($ar1) != count($ar2)) {
        return FALSE;
    }
    $diff = array_diff($ar1, $ar2);
    if (count($diff) == 0) {
        return TRUE;
    }
    # diff failed, do a full check of the array
    foreach ($ar1 as $k => $v) {
        #print "comparing $v == $ar2[$k]\n";
        if (gettype($v) == "array") {
            if (!array_compare($v, $ar2[$k])) {
                return FALSE;
            }
        } else {
            if (!string_compare($v, $ar2[$k])) {
                return FALSE;
            }
            if ($type == 'float') {
                # we'll only compare to 3 digits of precision
                $ok = number_compare($expect, $result, 3);
            }
            if ($type == 'boolean') {
                $ok = boolean_compare($expect, $result);
            } else {
                $ok = string_compare($expect, $result);
            }
        }
    }
    return TRUE;
}
开发者ID:abhinay100,项目名称:fengoffice_app,代码行数:37,代码来源:interop_test_functions.php

示例12: removeSimilarGrants

 function removeSimilarGrants($grants)
 {
     // first check for similar grants (same modifiers)
     $grants_check = $grants;
     foreach ($grants as $grant => $grant_ar) {
         // loop $grants for each entry in $grants_check (which is a copy)
         array_shift($grants_check);
         if (is_array($grant_ar)) {
             foreach ($grants_check as $grant_c => $grant_ar_c) {
                 if (is_array($grant_ar_c) && array_compare($grant_ar, $grant_ar_c)) {
                     unset($grants[$grant_c]);
                 }
             }
         }
     }
     reset($grants);
     ksort($grants);
     return $grants;
 }
开发者ID:poef,项目名称:ariadne,代码行数:19,代码来源:dialog.grants.logic.php

示例13: compareResult

 /**
  * Compares two PHP types for a match.
  *
  * @param mixed $expect
  * @param mixed $test_result
  *
  * @return boolean
  */
 function compareResult(&$expect, &$result, $type = null)
 {
     $expect_type = gettype($expect);
     $result_type = gettype($result);
     if ($expect_type == 'array' && $result_type == 'array') {
         // compare arrays
         return array_compare($expect, $result);
     }
     if ($type == 'float') {
         // We'll only compare to 3 digits of precision.
         return number_compare($expect, $result);
     }
     if ($type == 'boolean') {
         return boolean_compare($expect, $result);
     }
     return string_compare($expect, $result);
 }
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:25,代码来源:interop_client.php

示例14: save

 /** public function save
  *		Saves all changed data to the database
  *
  * @param void
  * @action saves the game data
  * @return void
  */
 public function save()
 {
     call(__METHOD__);
     // grab the base game data
     $query = "\n\t\t\tSELECT state\n\t\t\t\t, extra_info\n\t\t\t\t, modify_date\n\t\t\tFROM " . self::GAME_TABLE . "\n\t\t\tWHERE game_id = '{$this->id}'\n\t\t\t\tAND state <> 'Waiting'\n\t\t";
     $game = $this->_mysql->fetch_assoc($query);
     call($game);
     $update_modified = false;
     if (!$game) {
         throw new MyException(__METHOD__ . ': Game data not found for game #' . $this->id);
     }
     $this->_log('DATA SAVE: #' . $this->id . ' @ ' . time() . "\n" . ' - ' . $this->modify_date . "\n" . ' - ' . strtotime($game['modify_date']));
     // test the modified date and make sure we still have valid data
     call($this->modify_date);
     call(strtotime($game['modify_date']));
     if ($this->modify_date != strtotime($game['modify_date'])) {
         $this->_log('== FAILED ==');
         throw new MyException(__METHOD__ . ': Trying to save game (#' . $this->id . ') with out of sync data');
     }
     $update_game = false;
     call($game['state']);
     call($this->state);
     if ($game['state'] != $this->state) {
         $update_game['state'] = $this->state;
         if ('Finished' == $this->state) {
             $update_game['winner_id'] = $this->_players[$this->_pharaoh->winner]['player_id'];
         }
         if (in_array($this->state, array('Finished', 'Draw'))) {
             try {
                 $this->_add_stats();
             } catch (MyException $e) {
                 // do nothing, it gets logged
             }
         }
     }
     $diff = array_compare($this->_extra_info, self::$_EXTRA_INFO_DEFAULTS);
     $update_game['extra_info'] = $diff[0];
     ksort($update_game['extra_info']);
     $update_game['extra_info'] = serialize($update_game['extra_info']);
     if ('a:0:{}' == $update_game['extra_info']) {
         $update_game['extra_info'] = null;
     }
     if (0 === strcmp($game['extra_info'], $update_game['extra_info'])) {
         unset($update_game['extra_info']);
     }
     if ($update_game) {
         $update_modified = true;
         $this->_mysql->insert(self::GAME_TABLE, $update_game, " WHERE game_id = '{$this->id}' ");
     }
     // update the board
     $color = $this->_players['player']['color'];
     call($color);
     call('IN-GAME SAVE');
     // grab the current board from the database
     $query = "\n\t\t\tSELECT *\n\t\t\tFROM " . self::GAME_HISTORY_TABLE . "\n\t\t\tWHERE game_id = '{$this->id}'\n\t\t\tORDER BY move_date DESC\n\t\t\tLIMIT 1\n\t\t";
     $move = $this->_mysql->fetch_assoc($query);
     $board = $move['board'];
     call($board);
     $new_board = packFEN($this->_pharaoh->get_board());
     call($new_board);
     list($new_move, $new_hits) = $this->_pharaoh->get_move();
     call($new_move);
     call($new_hits);
     if (is_array($new_hits)) {
         $new_hits = implode(',', $new_hits);
     }
     if ($new_board != $board) {
         call('UPDATED BOARD');
         $update_modified = true;
         $this->_current_move_extra_info['laser_fired'] = (bool) $this->can_fire_laser();
         $this->_current_move_extra_info['laser_hit'] = (bool) $this->_pharaoh->laser_hit;
         $diff = array_compare($this->_current_move_extra_info, self::$_HISTORY_EXTRA_INFO_DEFAULTS);
         $m_extra_info = $diff[0];
         ksort($m_extra_info);
         $m_extra_info = serialize($m_extra_info);
         if ('a:0:{}' == $m_extra_info) {
             $m_extra_info = null;
         }
         $this->_mysql->insert(self::GAME_HISTORY_TABLE, array('board' => $new_board, 'move' => $new_move, 'hits' => $new_hits, 'extra_info' => $m_extra_info, 'game_id' => $this->id));
     }
     // update the game modified date
     if ($update_modified) {
         $this->_mysql->insert(self::GAME_TABLE, array('modify_date' => NULL), " WHERE game_id = '{$this->id}' ");
     }
 }
开发者ID:benjamw,项目名称:pharaoh,代码行数:92,代码来源:game.class.php

示例15: array_compare

function array_compare($needle, $haystack, $match_all = true)
{
    if (!is_array($needle) || count($haystack) > count($needle)) {
        return false;
    }
    $count = 0;
    $result = false;
    foreach ($needle as $k => $v) {
        if (!isset($haystack[$k])) {
            if ($match_all) {
                return false;
            }
            continue;
        }
        if (is_array($v)) {
            $result = array_compare($v, $haystack[$k], $match_all);
        }
        $result = $haystack[$k] === $v && ($match_all && (!$count || $result) || !$match_all) || !$match_all && $result;
        $count++;
    }
    return $result;
}
开发者ID:nopticon,项目名称:npt,代码行数:22,代码来源:functions.php


注:本文中的array_compare函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。