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


PHP array_udiff_assoc函数代码示例

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


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

示例1: get_changed_keys

 public static function get_changed_keys($old_value, $new_value, $deep = false)
 {
     if (!is_array($old_value) && !is_array($new_value)) {
         return array();
     }
     if (!is_array($old_value)) {
         return array_keys($new_value);
     }
     if (!is_array($new_value)) {
         return array_keys($old_value);
     }
     $diff = array_udiff_assoc($old_value, $new_value, function ($value1, $value2) {
         return maybe_serialize($value1) !== maybe_serialize($value2);
     });
     $result = array_keys($diff);
     // find unexisting keys in old or new value
     $common_keys = array_keys(array_intersect_key($old_value, $new_value));
     $unique_keys_old = array_values(array_diff(array_keys($old_value), $common_keys));
     $unique_keys_new = array_values(array_diff(array_keys($new_value), $common_keys));
     $result = array_merge($result, $unique_keys_old, $unique_keys_new);
     // remove numeric indexes
     $result = array_filter($result, function ($value) {
         // check if is not valid number (is_int, is_numeric and ctype_digit are not enough)
         return (string) (int) $value !== (string) $value;
     });
     $result = array_values(array_unique($result));
     if (false === $deep) {
         return $result;
         // Return an numerical based array with changed TOP PARENT keys only
     }
     $result = array_fill_keys($result, null);
     foreach ($result as $key => $val) {
         if (in_array($key, $unique_keys_old)) {
             $result[$key] = false;
             // Removed
         } elseif (in_array($key, $unique_keys_new)) {
             $result[$key] = true;
             // Added
         } elseif ($deep) {
             // Changed, find what changed, only if we're allowed to explore a new level
             if (is_array($old_value[$key]) && is_array($new_value[$key])) {
                 $inner = array();
                 $parent = $key;
                 $deep--;
                 $changed = self::get_changed_keys($old_value[$key], $new_value[$key], $deep);
                 foreach ($changed as $child => $change) {
                     $inner[$parent . '::' . $child] = $change;
                 }
                 $result[$key] = 0;
                 // Changed parent which has a changed children
                 $result = array_merge($result, $inner);
             }
         }
     }
     return $result;
 }
开发者ID:HasClass0,项目名称:mainwp-child-reports,代码行数:56,代码来源:connector.php

示例2: getChanges

 /**
  * Function to retrive the changed fields of an entity
  * 
  * @param bool $original retrieve the original values 
  * @return array of changed values
  */
 public function getChanges($original = false)
 {
     $a = $original ? $this->cleanData : $this->toArray(false);
     $b = $original ? $this->toArray(false) : $this->cleanData;
     return array_udiff_assoc($a, $b, function ($a, $b) {
         if (is_array($a) || is_array($b)) {
             return 0;
         }
         if ($a !== $b) {
             return 1;
         }
         return 0;
     });
 }
开发者ID:MagmaDigitalLtd,项目名称:ZucchiDoctrine,代码行数:20,代码来源:ChangeTrackingTrait.php

示例3: onLinksUpdate

 function onLinksUpdate(&$linksUpdate)
 {
     $oldILL = $this->getILL(DB_SLAVE, $linksUpdate->mTitle);
     $newILL = $linksUpdate->mInterlangs;
     //Convert $newILL to the same format as $oldILL
     foreach ($newILL as $k => $v) {
         if (!is_array($v)) {
             $newILL[$k] = array($v => true);
         }
     }
     //Compare ILLs before and after the save; if nothing changed, there is no need to purge
     if (count(array_udiff_assoc($oldILL, $newILL, "InterlanguageCentralExtension::arrayCompareKeys")) || count(array_udiff_assoc($newILL, $oldILL, "InterlanguageCentralExtension::arrayCompareKeys"))) {
         $ill = array_merge_recursive($oldILL, $newILL);
         $job = new InterlanguageCentralExtensionPurgeJob($linksUpdate->mTitle, array('ill' => $ill));
         $job->insert();
     }
     return true;
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:18,代码来源:InterlanguageCentralExtension.php

示例4: mergeTopLevelLinks

 /**
  * @param array &$champion
  * @param array $challenger
  * @return self
  */
 public function mergeTopLevelLinks(array &$champion, array $challenger)
 {
     static $key = 'links';
     if (isset($champion[$key]) || isset($challenger[$key])) {
         if (empty($champion[$key])) {
             $champion[$key] = $challenger[$key];
         } elseif (!empty($challenger[$key])) {
             $links = array_merge($champion[$key], $challenger[$key]);
             $compare = function (array $linkA, array $linkB) {
                 $comparison = (int) ($linkA !== $linkB);
                 return $comparison;
             };
             $diff = array_udiff_assoc($champion[$key], $links, $compare);
             if (!empty($diff)) {
                 throw new \LogicException(self::ERROR_MISSING_TOP_LEVEL_LINKS);
             } else {
                 $champion[$key] = $links;
             }
         }
     }
     return $this;
 }
开发者ID:gointegro,项目名称:hateoas,代码行数:27,代码来源:Blender.php

示例5: array_udiff_assoc

<?php

/* Prototype  : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func)
 * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. 
 * Source code: ext/standard/array.c
 * Alias to functions: 
 */
echo "*** Testing array_udiff_assoc() : variation - testing with multiple array arguments ***\n";
include 'compare_function.inc';
$key_compare_function = 'compare_function';
// Initialise all required variables
$arr1 = array("one" => "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 6.0 => 6, "seven" => "0x7");
$arr2 = array("one" => "one", "02" => "two", '3' => "three");
$arr3 = array("four", "0.5" => "five", 6 => 6, "seven" => 7);
$arr4 = array("four", "0.5" => "five", 6 => 6, "seven" => 7);
var_dump(array_udiff_assoc($arr1, $arr2, $arr3, $arr4, $key_compare_function));
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:array_udiff_assoc_variation.php

示例6: array_combine

}), array_combine($names, $names)), array_product($names), array_search(array_unique(array_count_values(array_merge_recursive($names, array_pad(array_replace_recursive($names, array_intersect_uassoc($names, $names, function ($a, $b) {
    return $a > $b;
})), array_key_exists((int) array_walk($names, function ($v, $k) {
    return $k;
}), $names), array_walk_recursive($names, function ($v, $k) {
    return $k;
}))))), $names))), function ($a, $b) {
    return $a > $b;
}), function ($a, $b) {
    return $b > $a;
}, function ($a, $b) {
    return $b > $a;
})), array_splice($names, array_multisort(array_map(function ($v) {
    return $v;
}, array_intersect_ukey(array_diff_key($names, array_udiff_assoc($names, $names, function ($a, $b) {
    return $a > $b;
})), $names, function ($a, $b) use($names) {
    return array_push($names, $a) === $b;
})))), function ($a, $b) {
    return $a;
})))), function ($v) {
    if ($v !== '' && $v !== 'Rick Astley') {
        return true;
    }
    return false;
}))) . "!\n";
/*
  Step 1: separate the functions by return value scalar/array
  Step 2: further separate by type, and type of array
  Step 3: pair similar functions together
  Step 4: tackle the hard functions first (indicated with *)
开发者ID:rpkamp,项目名称:rafflers,代码行数:31,代码来源:raffler.php

示例7: array_udiff_assoc

<?php

// array_udiff_assoc_diffkeys.php
$week = ["Monday" => "Rāhina", "Tuesday" => "Rātū", "Wednesday" => "Rāapa", "Thursday" => "Rāpare", "Friday" => "Rāmere", "Saturday" => "Rāhoroi", "Sunday" => "Rātapu"];
$weekend = ["Samedi" => "Rāhoroi", "Dimanche" => "Rātapu"];
$weekdays = array_udiff_assoc($week, $weekend, function ($v1, $v2) {
    echo "{$v1}:{$v2}<br>";
    if ($v1 == $v2) {
        return 0;
    }
    return $v1 > $v2 ? 1 : -1;
});
echo "<pre>";
var_dump($weekdays);
echo "</pre>";
开发者ID:JoshuaReneDalley,项目名称:php,代码行数:15,代码来源:array_udiff_assoc_diffkeys.php

示例8: doGenerate


//.........这里部分代码省略.........
                 // check requirement
                 if (null !== $this->strictRequirements && !preg_match('#^' . $token[2] . '$#', $mergedParams[$token[3]])) {
                     $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
                     if ($this->strictRequirements) {
                         throw new InvalidParameterException($message);
                     }
                     if ($this->logger) {
                         $this->logger->error($message);
                     }
                     return;
                 }
                 $url = $token[1] . $mergedParams[$token[3]] . $url;
                 $optional = false;
             }
         } else {
             // static text
             $url = $token[1] . $url;
             $optional = false;
         }
     }
     if ('' === $url) {
         $url = '/';
     }
     // the contexts base URL is already encoded (see Symfony\Component\HttpFoundation\Request)
     $url = strtr(rawurlencode($url), $this->decodedChars);
     // the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
     // so we need to encode them as they are not used for this purpose here
     // otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
     $url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
     if ('/..' === substr($url, -3)) {
         $url = substr($url, 0, -2) . '%2E%2E';
     } elseif ('/.' === substr($url, -2)) {
         $url = substr($url, 0, -1) . '%2E';
     }
     $schemeAuthority = '';
     if ($host = $this->context->getHost()) {
         $scheme = $this->context->getScheme();
         if ($requiredSchemes) {
             if (!in_array($scheme, $requiredSchemes, true)) {
                 $referenceType = self::ABSOLUTE_URL;
                 $scheme = current($requiredSchemes);
             }
         } elseif (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
             // We do this for BC; to be removed if _scheme is not supported anymore
             $referenceType = self::ABSOLUTE_URL;
             $scheme = $req;
         }
         if ($hostTokens) {
             $routeHost = '';
             foreach ($hostTokens as $token) {
                 if ('variable' === $token[0]) {
                     if (null !== $this->strictRequirements && !preg_match('#^' . $token[2] . '$#i', $mergedParams[$token[3]])) {
                         $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
                         if ($this->strictRequirements) {
                             throw new InvalidParameterException($message);
                         }
                         if ($this->logger) {
                             $this->logger->error($message);
                         }
                         return;
                     }
                     $routeHost = $token[1] . $mergedParams[$token[3]] . $routeHost;
                 } else {
                     $routeHost = $token[1] . $routeHost;
                 }
             }
             if ($routeHost !== $host) {
                 $host = $routeHost;
                 if (self::ABSOLUTE_URL !== $referenceType) {
                     $referenceType = self::NETWORK_PATH;
                 }
             }
         }
         if (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) {
             $port = '';
             if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
                 $port = ':' . $this->context->getHttpPort();
             } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
                 $port = ':' . $this->context->getHttpsPort();
             }
             $schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : "{$scheme}://";
             $schemeAuthority .= $host . $port;
         }
     }
     if (self::RELATIVE_PATH === $referenceType) {
         $url = self::getRelativePath($this->context->getPathInfo(), $url);
     } else {
         $url = $schemeAuthority . $this->context->getBaseUrl() . $url;
     }
     // add a query string if needed
     $extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, function ($a, $b) {
         return $a == $b ? 0 : 1;
     });
     if ($extra && ($query = http_build_query($extra, '', '&'))) {
         // "/" and "?" can be left decoded for better user experience, see
         // http://tools.ietf.org/html/rfc3986#section-3.4
         $url .= '?' . strtr($query, array('%2F' => '/'));
     }
     return $url;
 }
开发者ID:nakigao,项目名称:nakigaos-trpg-room-web,代码行数:101,代码来源:UrlGenerator.php

示例9: getMenuStyle

 /**
  * Recursively drop back to the parents menu style
  * when the current menu has a parent and has no changes
  *
  * @return MenuStyle
  */
 private function getMenuStyle()
 {
     $diff = array_udiff_assoc($this->style, $this->getStyleClassDefaults(), function ($current, $default) {
         if ($current instanceof TerminalInterface) {
             return 0;
         }
         return $current === $default ? 0 : 1;
     });
     if (!$diff && null !== $this->parent) {
         return $this->parent->getMenuStyle();
     }
     return new MenuStyle(...array_values($this->style));
 }
开发者ID:aminubakori,项目名称:cli-menu,代码行数:19,代码来源:CliMenuBuilder.php

示例10: getDeleteDiff

 public function getDeleteDiff()
 {
     $this->initialize();
     return array_udiff_assoc($this->snapshot, $this->collection->toArray(), function ($a, $b) {
         return $a === $b ? 0 : 1;
     });
 }
开发者ID:activelamp,项目名称:taxonomy,代码行数:7,代码来源:PluralVocabularyField.php

示例11: array_udiff_assoc

<?php

/* Prototype  : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func)
 * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. 
 * Source code: ext/standard/array.c
 * Alias to functions: 
 */
echo "*** Testing array_udiff_assoc() : usage variation - differing comparison functions***\n";
$arr1 = array(1);
$arr2 = array(1, 2);
echo "\n-- comparison function with an incorrect return value --\n";
function incorrect_return_value($val1, $val2)
{
    return array(1);
}
var_dump(array_udiff_assoc($arr1, $arr2, 'incorrect_return_value'));
echo "\n-- comparison function taking too many parameters --\n";
function too_many_parameters($val1, $val2, $val3)
{
    return 1;
}
var_dump(array_udiff_assoc($arr1, $arr2, 'too_many_parameters'));
echo "\n-- comparison function taking too few parameters --\n";
function too_few_parameters($val1)
{
    return 1;
}
var_dump(array_udiff_assoc($arr1, $arr2, 'too_few_parameters'));
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:array_udiff_assoc_variation5.php

示例12: calculateConfigChangeSet

 /**
  * @param ConfigInterface $config
  * @SuppressWarnings(PHPMD)
  */
 public function calculateConfigChangeSet(ConfigInterface $config)
 {
     $originConfigValue = [];
     $configKey = $this->buildConfigKey($config->getId());
     if (isset($this->originalConfigs[$configKey])) {
         $originConfigValue = $this->originalConfigs[$configKey]->all();
     }
     foreach ($config->all() as $key => $value) {
         if (!isset($originConfigValue[$key])) {
             $originConfigValue[$key] = null;
         }
     }
     $diffNew = array_udiff_assoc($config->all(), $originConfigValue, function ($a, $b) {
         return $a == $b ? 0 : 1;
     });
     $diffOld = array_udiff_assoc($originConfigValue, $config->all(), function ($a, $b) {
         return $a == $b ? 0 : 1;
     });
     $diff = [];
     foreach ($diffNew as $key => $value) {
         $oldValue = isset($diffOld[$key]) ? $diffOld[$key] : null;
         $diff[$key] = [$oldValue, $value];
     }
     if (!isset($this->configChangeSets[$configKey])) {
         $this->configChangeSets[$configKey] = [];
     }
     if (count($diff)) {
         $changeSet = array_merge($this->configChangeSets[$configKey], $diff);
         $this->configChangeSets[$configKey] = $changeSet;
     }
 }
开发者ID:nmallare,项目名称:platform,代码行数:35,代码来源:ConfigManager.php

示例13: getInsertDiff

 /**
  * INTERNAL:
  * getInsertDiff
  *
  * @return array
  */
 public function getInsertDiff()
 {
     return array_udiff_assoc($this->coll->toArray(), $this->snapshot, array(__CLASS__, 'strictDiffCompare'));
 }
开发者ID:nicolas-grekas,项目名称:Patchwork-Doctrine,代码行数:10,代码来源:PersistentCollection.php

示例14: extractCommonParentNode

 /**
  * @param \Viserio\Routing\Generator\RouteTreeNode $node1
  * @param \Viserio\Routing\Generator\RouteTreeNode $node2
  *
  * @return \Viserio\Routing\Generator\RouteTreeNode|null
  */
 protected function extractCommonParentNode(RouteTreeNode $node1, RouteTreeNode $node2)
 {
     $matcherCompare = function (SegmentMatcherContract $matcher, SegmentMatcherContract $matcher2) {
         return strcmp($matcher->getHash(), $matcher2->getHash());
     };
     $commonMatchers = array_uintersect_assoc($node1->getMatchers(), $node2->getMatchers(), $matcherCompare);
     if (empty($commonMatchers)) {
         return;
     }
     $children = [];
     $nodes = [$node1, $node2];
     foreach ($nodes as $node) {
         $specificMatchers = array_udiff_assoc($node->getMatchers(), $commonMatchers, $matcherCompare);
         $duplicateMatchers = array_uintersect_assoc($node->getMatchers(), $commonMatchers, $matcherCompare);
         foreach ($duplicateMatchers as $segmentDepth => $matcher) {
             $commonMatchers[$segmentDepth]->mergeParameterKeys($matcher);
         }
         if (empty($specificMatchers) && $node->isParentNode()) {
             foreach ($node->getContents()->getChildren() as $childNode) {
                 $children[] = $childNode;
             }
         } else {
             $children[] = $node->update($specificMatchers, $node->getContents());
         }
     }
     return new RouteTreeNode($commonMatchers, new ChildrenNodeCollection($children));
 }
开发者ID:narrowspark,项目名称:framework,代码行数:33,代码来源:RouteTreeOptimizer.php

示例15: getDirties

 public function getDirties()
 {
     $to_insert = $this->getInsertDiff();
     $remaining = array_udiff_assoc($this->items, $to_insert, function ($a, $b) {
         return $a === $b ? 0 : 1;
     });
     $dirties = array();
     if (count($remaining) == 0) {
         return $dirties;
     }
     foreach ($remaining as $r) {
         if ($r->isChanged()) {
             array_push($dirties, $r);
         }
     }
     return $dirties;
 }
开发者ID:Thingee,项目名称:openstack-org,代码行数:17,代码来源:PersistentCollection.php


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