示例#1
0
文件: TestCase.php 项目: vgrish/tacit
 /**
  * Recursively compare multi-dimensional associative array items.
  *
  * @param mixed $val1
  * @param mixed $val2
  *
  * @return int 0 if equal, non-zero otherwise
  */
 public function compareMultidimensionalArray($val1, $val2)
 {
     if (is_array($val1) && is_array($val2)) {
         $arr = array_uintersect_assoc($val1, $val2, array($this, 'compareMultidimensionalArray'));
         if (count($arr) == max(count($val1), count($val2))) {
             return 0;
         }
         return -1;
     }
     return strcmp($val1, $val2);
 }
示例#2
0
 /**
  * @param string $path
  * @param array  $params
  * @return bool True if path/queries match
  */
 public final function compare($path, array $params = array())
 {
     /** @var CM_Page_Abstract $pageClassName */
     $pageClassName = $this->getPageName();
     $pathMatch = $path == $pageClassName::getPath();
     if ($pathMatch) {
         $paramsMatch = array_uintersect_assoc($this->getParams(), $params, function ($a, $b) {
             if (is_array($a) && is_array($b)) {
                 return array_diff_assoc($a, $b) === array_diff_assoc($b, $a) ? 0 : -1;
             } elseif (is_array($a) || is_array($b)) {
                 return -1;
             }
             return (string) $a === (string) $b ? 0 : -1;
         }) == $this->getParams();
         return $paramsMatch;
     }
     return false;
 }
示例#3
0
 /**
  * Create a new Balancer.
  * @param array $config Balancer configuration.  Includes:
  *     'strict' : boolean, defaults to false.
  *         When true, enforces syntactic constraints on input:
  *         all non-tag '<' must be escaped, all attributes must be
  *         separated by a single space and double-quoted.  This is
  *         consistent with the output of the Sanitizer.
  *     'allowedHtmlElements' : array, defaults to null.
  *         When present, the keys of this associative array give
  *         the acceptable HTML tag names.  When not present, no
  *         tag sanitization is done.
  *     'tidyCompat' : boolean, defaults to false.
  *         When true, the serialization algorithm is tweaked to
  *         provide historical compatibility with the old "tidy"
  *         program: <p>-wrapping is done to the children of
  *         <body> and <blockquote> elements, and empty elements
  *         are removed.
  *     'allowComments': boolean, defaults to true.
  *         When true, allows HTML comments in the input.
  *         The Sanitizer generally strips all comments, so if you
  *         are running on sanitized output you can set this to
  *         false to get a bit more performance.
  */
 public function __construct(array $config = [])
 {
     $this->config = $config = $config + ['strict' => false, 'allowedHtmlElements' => null, 'tidyCompat' => false, 'allowComments' => true];
     $this->allowedHtmlElements = $config['allowedHtmlElements'];
     $this->strict = $config['strict'];
     $this->allowComments = $config['allowComments'];
     if ($this->allowedHtmlElements !== null) {
         // Sanity check!
         $bad = array_uintersect_assoc($this->allowedHtmlElements, BalanceSets::$unsupportedSet[BalanceSets::HTML_NAMESPACE], function ($a, $b) {
             // Ignore the values (just intersect the keys) by saying
             // all values are equal to each other.
             return 0;
         });
         if (count($bad) > 0) {
             $badstr = implode(array_keys($bad), ',');
             throw new ParameterAssertionException('$config', 'Balance attempted with sanitization including ' . "unsupported elements: {$badstr}");
         }
     }
 }
 /**
  * @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));
 }
示例#5
0
 public static function loadConfig($file = NULL, $force = false)
 {
     //If no attempt has been made to load the config, attempt to load it, and patch it over $configData
     if (!is_bool($force)) {
         throw new UserInvalidModeException('loadConfig', $force, 'false (don\'t force), true (force)');
     }
     if (User::$configLoaded && !$force) {
         return;
     }
     $pairs = NULL;
     $pathRegex = '%^(?:~?/|[A-Z]:[\\\\/]).+%i';
     if ($file === NULL) {
         $file = User::DEFAULT_CONFIG_FILE;
         if (!preg_match($pathRegex, User::DEFAULT_CONFIG_FILE)) {
             $file = __DIR__ . '/' . $file;
         }
         if (is_file($file) && is_readable($file)) {
             $pairs = array_change_key_case(parse_ini_file($file));
         }
     } else {
         if (!is_file($file)) {
             throw new UserIncorrectDatatypeException('loadConfig()', 1, 'file path', $file);
         } else {
             if (!is_readable($file)) {
                 throw new UserFileUnreadableException('loadConfig()', $file);
             } else {
                 $pairs = array_change_key_case(parse_ini_file($file));
             }
         }
     }
     if ($pairs) {
         $pairs = array_uintersect_assoc($pairs, User::$configData, create_function(NULL, "return 0;"));
         User::$configData = array_merge(User::$configData, $pairs);
     }
     //Convert relative db_path values to absolute, taking '.' to be the parent directory of User.php
     if (!preg_match($pathRegex, User::$configData['db_path'])) {
         User::$configData['db_path'] = __DIR__ . '/' . User::$configData['db_path'];
     }
     User::$configLoaded = true;
 }
    {
        $this->priv_member = $val;
    }
    function comp_func_cr($a, $b)
    {
        if ($a->priv_member === $b->priv_member) {
            return 0;
        }
        return $a->priv_member > $b->priv_member ? 1 : -1;
    }
    function comp_func_key($a, $b)
    {
        if ($a === $b) {
            return 0;
        }
        return $a > $b ? 1 : -1;
    }
}
$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15));
$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15));
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
print_r(array_udiff($a, $b, array("cr", "comp_func_cr")));
print_r(array_udiff_assoc($a, $b, array("cr", "comp_func_cr")));
print_r(array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")));
print_r(array_diff_uassoc($array1, $array2, "key_compare_func"));
print "------------------------------------\n";
print_r(array_uintersect($a, $b, array("cr", "comp_func_cr")));
print_r(array_uintersect_assoc($a, $b, array("cr", "comp_func_cr")));
print_r(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")));
print_r(array_intersect_uassoc($array1, $array2, "key_compare_func"));
//get an unset variable
$unset_var = 10;
unset($unset_var);
// define some classes
class classWithToString
{
    public function __toString()
    {
        return "Class A object";
    }
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array(1, 2, 3);
$assoc_array = array('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -2345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float 12.3456789000e10' => 123456789000.0, 'float -12.3456789000e10' => -123456789000.0, 'float .5' => 0.5, 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var);
// loop through each element of the array for ...
foreach ($inputs as $key => $value) {
    echo "\n--{$key}--\n";
    var_dump(array_uintersect_assoc($arr1, $arr2, $value, $data_compare_function));
}
?>
===DONE===
示例#8
0
<?php

$names = file(realpath($argv[1]), FILE_IGNORE_NEW_LINES);
echo "And the WINNER is... " . array_rand(array_flip(array_filter(array_reverse(array_column(array_chunk(array_intersect($names, array_replace($names, array_change_key_case(array_fill_keys($names, 'Rick Astley')))), (int) @array_pop(array_fill(array_reduce(array_keys($names), function ($c, $a) {
    return $a;
}), array_unshift($names, 'Rick Astley'), '1 true love'))), array_sum(array_diff_ukey(array_intersect_key(array_diff_assoc(array_uintersect($names, array_intersect_assoc(array_uintersect_assoc($names, array_values($names), function ($a, $b) {
    return $b > $a;
}), $names), function ($a, $b) use($names) {
    return array_shift($names) > $b;
}), array()), array_uintersect_uassoc($names, array_udiff($names, array_diff($names, array_slice(array_merge(array_diff_uassoc(array_udiff_uassoc($names, $names, function ($a, $b) {
    return $b > $a;
}, function ($a, $b) {
    return $b > $a;
}), $names, function ($a, $b) {
    return $a > $b;
}), 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;
示例#9
0
 /**
  * Test a RESTful PUT request on a RestfulItem
  *
  * @param array $data
  *
  * @group controller
  *
  * @dataProvider providerPut
  */
 public function testPut(array $data)
 {
     /** @var MockPersistent $itemObj */
     $itemObj = MockPersistent::findOne(['name' => $data['name']], [], $this->fixture);
     $this->mockEnvironment(['PATH_INFO' => '/collection/' . $itemObj->_id, 'REQUEST_METHOD' => 'PUT', 'CONTENT_TYPE' => 'application/json', 'slim.input' => json_encode($data)]);
     try {
         $response = $this->tacit->invoke();
         $item = json_decode($response->getBody(), true);
         unset($data['password']);
         $matches = array_uintersect_assoc($data, $item, array($this, 'compareMultidimensionalArray'));
         $this->assertEquals($data, $matches);
     } catch (RestfulException $e) {
         $this->fail($e->getMessage());
     } catch (\Exception $e) {
         $this->fail($e->getMessage());
     }
 }
示例#10
0
 /**
  * @param CM_Db_Client      $client
  * @param string            $table
  * @param string|array      $fields    Column-name OR Column-names array
  * @param array[]           $whereList Outer array-entries are combined using OR, inner arrays using AND
  * @param string|array|null $order
  */
 public function __construct(CM_Db_Client $client, $table, $fields, array $whereList, $order = null)
 {
     parent::__construct($client);
     $fields = (array) $fields;
     foreach ($fields as &$field) {
         if ($field == '*') {
             $field = '*';
         } else {
             $field = $this->_getClient()->quoteIdentifier($field);
         }
     }
     $this->_addSql('SELECT ' . implode(',', $fields));
     $this->_addSql('FROM ' . $this->_getClient()->quoteIdentifier($table));
     if (!empty($whereList)) {
         $wherePartCommon = array();
         if (count($whereList) >= 2) {
             $wherePartCommon = reset($whereList);
             foreach ($whereList as $wherePart) {
                 $wherePartCommon = array_uintersect_assoc($wherePartCommon, $wherePart, function ($a, $b) {
                     return $a !== $b;
                 });
             }
         }
         $whereParts = array();
         foreach ($whereList as $wherePart) {
             $sqlParts = array();
             $wherePartFiltered = array_udiff_assoc($wherePart, $wherePartCommon, function ($a, $b) {
                 return $a !== $b;
             });
             if (!empty($wherePartFiltered)) {
                 foreach ($wherePartFiltered as $field => $value) {
                     if (null === $value) {
                         $sqlParts[] = $this->_getClient()->quoteIdentifier($field) . ' IS NULL';
                     } else {
                         $sqlParts[] = $this->_getClient()->quoteIdentifier($field) . ' = ?';
                         $this->_addParameters($value);
                     }
                 }
                 $whereParts[] = implode(' AND ', $sqlParts);
             }
         }
         if (empty($wherePartCommon)) {
             $this->_addSql('WHERE ' . implode(' OR ', $whereParts));
         } else {
             if (!empty($whereParts)) {
                 $this->_addSql('WHERE (' . implode(' OR ', $whereParts) . ') AND');
             } else {
                 $this->_addSql('WHERE');
             }
             $sqlParts = array();
             foreach ($wherePartCommon as $field => $value) {
                 if (null === $value) {
                     $sqlParts[] = $this->_getClient()->quoteIdentifier($field) . ' IS NULL';
                 } else {
                     $sqlParts[] = $this->_getClient()->quoteIdentifier($field) . ' = ?';
                     $this->_addParameters($value);
                 }
             }
             $this->_addSql(implode(' AND ', $sqlParts));
         }
     }
     $this->_addOrderBy($order);
 }
//get an unset variable
$unset_var = 10;
unset($unset_var);
// define some classes
class classWithToString
{
    public function __toString()
    {
        return "Class A object";
    }
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array(1, 2, 3);
$assoc_array = array('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -2345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float 12.3456789000e10' => 123456789000.0, 'float -12.3456789000e10' => -123456789000.0, 'float .5' => 0.5, 'empty array' => array(), 'int indexed array' => $index_array, 'associative array' => $assoc_array, 'nested arrays' => array('foo', $index_array, $assoc_array), 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var);
// loop through each element of the array for data_compare_func
foreach ($inputs as $key => $value) {
    echo "\n--{$key}--\n";
    var_dump(array_uintersect_assoc($arr1, $arr2, $value));
}
?>
===DONE===
示例#12
0
 public function uintersect_assoc($aArray, $callback)
 {
     if ($aArray instanceof MF_PHP_Array) {
         $aArray =& $aArray->to_array();
     }
     $oReturn = new MF_PHP_Array(array_uintersect_assoc($this->__data, $aArray, $callback));
     return $oReturn;
 }
示例#13
0
 /**
  * Get key-value pairs which exist in both of two arrays.
  *
  * Returns an associative array whose key-value pairs exist in both
  * arrays. Uses string comparison for values by default. Optionally
  * provide comparison functions for keys and values.
  *
  * @param array $array1
  * @param array $array2
  * @param callable|null $key_cmp
  * @param callable|null $value_cmp
  * @return array
  */
 public static function pairIntersection($array1, $array2, $key_cmp = null, $value_cmp = null)
 {
     if ($key_cmp === null) {
         if ($value_cmp === null) {
             return array_intersect_assoc($array1, $array2);
         } else {
             return array_uintersect_assoc($array1, $array2, $value_cmp);
         }
     } else {
         if ($value_cmp === null) {
             return array_intersect_uassoc($array1, $array2, $key_cmp);
         } else {
             return array_uintersect_uassoc($array1, $array2, $value_cmp, $key_cmp);
         }
     }
 }
示例#14
0
 /**
  * @param HTArray $array2
  * @param $data_compare_func
  * @return $this
  * @desc 带索引检查计算数组的交集,用回调函数比较数据。
  */
 public function array_uintersect_assoc(HTArray $array2, $data_compare_func)
 {
     $this->current = array_uintersect_assoc($this->current, (array) $array2, $data_compare_func);
     return $this;
 }
/* Prototype  : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func)
 * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. 
 * Source code: ext/standard/array.c
 * Alias to functions: 
 */
echo "*** Testing array_uintersect_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_uintersect_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_uintersect_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_uintersect_assoc($arr1, $arr2, 'too_few_parameters'));
?>

===DONE===
示例#16
0
 /**
  * Prunes fields in an array of JContent objects to a set list.
  *
  * @param   mixed  $list    An array of JContent or a JContent object
  * @param   array  $fields  An array of the field names to preserve (strip all others).
  *
  * @return  mixed
  *
  * @since   1.0
  */
 protected function pruneFields($list, $fields)
 {
     if ($list == null) {
         return array();
     }
     // If a list of fields is passed
     if ($fields) {
         // Flip the fields so we can find the intersection by the array keys.
         $fields = array_flip($fields);
         // $list is an array of JContent
         if (is_array($list)) {
             /* @var $object JContent */
             foreach ($list as $key => $object) {
                 // Suck out only the fields we want from the object dump.
                 $list[$key] = array_uintersect_assoc((array) $object->dump(), $fields, create_function(null, 'return 0;'));
                 $list[$key] = $this->mapFieldsOut($list[$key]);
             }
         } else {
             $list = array_uintersect_assoc((array) $list->dump(), $fields, create_function(null, 'return 0;'));
             $list = $this->mapFieldsOut($list);
         }
     } else {
         // $list is an array of JContent
         if (is_array($list)) {
             foreach ($list as $key => $object) {
                 // Suck out only the fields we want from the object dump.
                 $list[$key] = (array) $object->dump();
                 $list[$key] = $this->mapFieldsOut($list[$key]);
             }
         } else {
             $list = (array) $list->dump();
             $list = $this->mapFieldsOut($list);
         }
     }
     return $list;
 }
示例#17
0
 /**
  * (PHP 5)<br/>
  * Computes the intersection of arrays with additional index check, compares data by a callback function
  * @link http://php.net/manual/en/function.array-uintersect-assoc.php
  * @param array $array2 <p>
  * The second array.
  * </p>
  * @param array $_ [optional]
  * @param callable $value_compare_func <p>
  * The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
  * </p>
  * int<b>callback</b><b>mixed<i>a</i></b><b>mixed<i>b</i></b>
  * @return array an array containing all the values of
  * <i>array1</i> that are present in all the arguments.
  */
 public function uintersect_assoc(array $array2, array $_ = null, callable $value_compare_func)
 {
     // TODO: use func_get_args() for multiple arguments, like Arr($array)->function($v1, $v2, $v3)
     return array_uintersect_assoc($this->array, $array2, $value_compare_func);
 }
示例#18
0
 /**
  * Return an array of key value pairs in $subject that are present in $pattern as glob matches.
  *
  * @param  array $subject
  * @param  array $pattern
  * @return array
  */
 private function getGlobMatches(array $subject, array $pattern)
 {
     return array_uintersect_assoc($subject, $pattern, function ($globPattern, $string) {
         return fnmatch($globPattern, $string) ? 0 : -1;
     });
 }
<?php

// array_uintersect_assoc.php
$week = ["Monday" => "Rāhina", "Tuesday" => "Rātū", "Wednesday" => "Rāapa", "Thursday" => "Rāpare", "Friday" => "Rāmere", "Saturday" => "Rāhoroi", "Sunday" => "Rātapu"];
$weekend = ["Saturday" => "Rāhoroi", "Sunday" => "Rātapu"];
$weekendDays = array_uintersect_assoc($week, $weekend, function ($v1, $v2) {
    echo "{$v1}:{$v2}<br>";
    if ($v1 == $v2) {
        return 0;
    }
    return $v1 > $v2 ? 1 : -1;
});
echo "<pre>";
var_dump($weekendDays);
echo "</pre>";
示例#20
0
 /**
  * 
  * get properties intersect
  * @param array $se1
  * @param array $se2
  */
 public static function getPropertiesIntersect($se1 = array(), $se2 = array())
 {
     $attrs1 = $se1['attrs'];
     $attrs2 = $se2['attrs'];
     $assoc = array_uintersect_assoc($attrs1, $attrs2, "Fl_Css_Static::checkPropertiesEqual");
     //if intersect attrs has hack attr, remove it
     foreach ($assoc as $name => $item) {
         if (preg_match(self::$multiSamePropertyPattern, $name)) {
             unset($assoc[$name]);
             continue;
         }
         $flag = false;
         foreach (self::$unMergeProperty as $key => $value) {
             if ($value === true) {
                 if ($name === $key) {
                     $flag = true;
                     break;
                 }
             } else {
                 //regexp
                 if ($value[0] === '/') {
                     if (preg_match($value, $item['value'])) {
                         $flag = true;
                         break;
                     }
                 }
             }
         }
         if ($flag) {
             unset($assoc[$name]);
             continue;
         }
         $flag = false;
         foreach (self::$unSortNames as $itemName) {
             if ($itemName == $name || strpos($name, $itemName . '-') !== false) {
                 $flag = true;
                 break;
             }
         }
         foreach ($attrs1 as $n1 => $i1) {
             if ($i1['property'] == $item['property'] && ($i1['prefix'] || $i1['suffix'])) {
                 unset($assoc[$name]);
                 break;
             }
             if ($i1['type'] === FL_TOKEN_CSS_HACK) {
                 return false;
             }
             if ($flag) {
                 if (strpos($name, '-') !== false) {
                     if (strpos($name, $i1['property'] . '-') !== false) {
                         unset($assoc[$name]);
                         break;
                     }
                 } else {
                     if (strpos($i1['property'], $name . '-') !== false) {
                         unset($assoc[$name]);
                         break;
                     }
                 }
             }
         }
         foreach ($attrs2 as $n1 => $i1) {
             if ($i1['property'] == $item['property'] && ($i1['prefix'] || $i1['suffix'])) {
                 unset($assoc[$name]);
                 break;
             }
             if ($i1['type'] === FL_TOKEN_CSS_HACK) {
                 return false;
             }
             if ($flag) {
                 if (strpos($name, '-') !== false) {
                     if (strpos($name, $i1['property'] . '-') !== false) {
                         unset($assoc[$name]);
                         break;
                     }
                 } else {
                     if (strpos($i1['property'], $name . '-') !== false) {
                         unset($assoc[$name]);
                         break;
                     }
                 }
             }
         }
     }
     if (empty($assoc)) {
         return false;
     }
     $assCount = count($assoc);
     if (count($attrs1) != $assCount && count($attrs2) !== $assCount) {
         // 3 chars is `, { }`
         $seLen = strlen($se1['selector']) + strlen($se2['selector']) + 3;
         $se1Equal = strlen(join(',', $se1['equal']));
         $se2Equal = strlen(join(',', $se2['equal']));
         if ($se1Equal) {
             $seLen += $se1Equal + 1;
         }
         if ($se2Equal) {
             $seLen += $se2Equal + 1;
         }
         $assLen = 0;
         foreach ($assoc as $item) {
             //2 chars is : and ;
             $assLen += strlen($item['prefix'] . $item['property'] . $item['value'] . $item['suffix']) + 2;
             //if have important in value, add `!important` length(10)
             if ($item['important']) {
                 $assLen += 10;
             }
         }
         $assLen--;
         //if combine selector length more than combine attrs, can't not combine them
         if ($seLen >= $assLen) {
             return false;
         }
     }
     return $assoc;
 }
<?php

/* Prototype  : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func)
 * Description: U
 * Source code: ext/standard/array.c
 * Alias to functions: 
 */
echo "*** Testing array_uintersect_assoc() : error conditions ***\n";
//Test array_uintersect_assoc with one more than the expected number of arguments
echo "\n-- Testing array_uintersect_assoc() function with more than expected no. of arguments --\n";
$arr1 = array(1, 2);
$arr2 = array(1, 2);
include 'compare_function.inc';
$data_compare_function = 'compare_function';
$extra_arg = 10;
var_dump(array_uintersect_assoc($arr1, $arr2, $data_compare_function, $extra_arg));
// Testing array_uintersect_assoc with one less than the expected number of arguments
echo "\n-- Testing array_uintersect_assoc() function with less than expected no. of arguments --\n";
$arr1 = array(1, 2);
$arr2 = array(1, 2);
var_dump(array_uintersect_assoc($arr1, $arr2));
?>
===DONE===
<?php

/*
* proto array array_uintersect_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] )
* Function is implemented in ext/standard/array.c
*/
class cr
{
    private $priv_member;
    function __construct($val)
    {
        $this->priv_member = $val;
    }
    static function comp_func_cr($a, $b)
    {
        if ($a->priv_member === $b->priv_member) {
            return 0;
        }
        return $a->priv_member > $b->priv_member ? 1 : -1;
    }
}
$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15));
$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15));
$result = array_uintersect_assoc($a, $b, array("cr", "comp_func_cr"));
var_dump($result);
}
$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15));
$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15));
/* array_uintersect() */
echo "begin ------------ array_uintersect() ---------------------------\n";
echo '$a=' . var_export($a, TRUE) . ";\n";
echo '$b=' . var_export($b, TRUE) . ";\n";
echo 'var_dump(array_uintersect($a, $b, "comp_func_cr"));' . "\n";
var_dump(array_uintersect($a, $b, "comp_func_cr"));
echo "end   ------------ array_uintersect() ---------------------------\n";
/* array_uintersect_assoc() */
echo "begin ------------ array_uintersect_assoc() ---------------------\n";
echo '$a=' . var_export($a, TRUE) . ";\n";
echo '$b=' . var_export($b, TRUE) . ";\n";
echo 'var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));' . "\n";
var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));
echo "end   ------------ array_uintersect_assoc() ---------------------\n";
/* array_uintersect_uassoc() - with ordinary function */
echo "begin ------------ array_uintersect_uassoc() with ordinary func -\n";
echo '$a=' . var_export($a, TRUE) . ";\n";
echo '$b=' . var_export($b, TRUE) . ";\n";
echo 'var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));' . "\n";
var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));
echo "end   ------------ array_uintersect_uassoc() with ordinary func -\n";
/* array_uintersect_uassoc() - by method call */
echo "begin ------------ array_uintersect_uassoc() with method --------\n";
echo '$a=' . var_export($a, TRUE) . ";\n";
echo '$b=' . var_export($b, TRUE) . ";\n";
echo 'var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));' . "\n";
var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));
echo "end   ------------ array_uintersect_uassoc() with method --------\n";
示例#24
0
<?php

$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red");
var_dump(array_uintersect_assoc($array1, $array2, 'strcasecmp'));