FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ArrayOperation.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Util;
9 
10 use Closure;
11 
13 {
18  public static function getMultiplicityOfValues($allValues)
19  {
20  $uniqueValues = array_unique($allValues);
21  $valueMultiplicityMap = array();
22 
23  foreach ($uniqueValues as $value) {
24  $count = 0;
25  foreach ($allValues as $candidate) {
26  if ($value == $candidate) {
27  $count ++;
28  }
29  }
30  $valueMultiplicityMap[$value] = $count;
31  }
32 
33  return $valueMultiplicityMap;
34  }
35 
36  public static function callChunked(Closure $callback, $values, $chunkSize)
37  {
38  if ($chunkSize <= 0) {
39  throw new \InvalidArgumentException('chunk size should be positive');
40  }
41  $result = array();
42  for ($offset = 0; $offset < count($values); $offset += $chunkSize) {
43  $result = array_merge($result,
44  $callback(array_slice($values, $offset, $chunkSize)));
45  }
46  return $result;
47  }
48 
49  public static function multiSearch($needles,$haystack)
50  {
51  foreach ($needles as $needle) {
52  $index = array_search($needle, $haystack);
53  if ($index !== false) {
54  return $index;
55  }
56  }
57  return false;
58  }
59 
73  public static function arrayKeysExists(array $array, array $keys): bool
74  {
75  return !array_diff_key(array_flip($keys), $array);
76  }
77 }
static arrayKeysExists(array $array, array $keys)
Check if a list of keys exists in associative array.
static getMultiplicityOfValues($allValues)