2023-07-04 06:26:08 +00:00
|
|
|
/**
|
|
|
|
* Check if have an array with a length
|
|
|
|
*
|
|
|
|
* @input array The array to check
|
|
|
|
*
|
|
|
|
* @returns int|false number of items in array on success
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public static function check($array, $removeEmptyString = false)
|
|
|
|
{
|
|
|
|
if (is_array($array) && ($nr = count((array) $array)) > 0)
|
|
|
|
{
|
|
|
|
// also make sure the empty strings are removed
|
|
|
|
if ($removeEmptyString)
|
|
|
|
{
|
|
|
|
$array = array_filter($array);
|
|
|
|
|
|
|
|
if ($array === [])
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge an array of array's
|
|
|
|
*
|
|
|
|
* @input array The arrays you would like to merge
|
|
|
|
*
|
|
|
|
* @returns array|null merged array on success
|
|
|
|
*
|
|
|
|
* @since 3.0.9
|
|
|
|
*/
|
|
|
|
public static function merge($arrays): ?array
|
|
|
|
{
|
|
|
|
if(self::check($arrays))
|
|
|
|
{
|
|
|
|
$merged = [];
|
|
|
|
foreach ($arrays as $array)
|
|
|
|
{
|
|
|
|
if (self::check($array))
|
|
|
|
{
|
|
|
|
$merged = array_merge($merged, $array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $merged;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if arrays intersect
|
|
|
|
*
|
|
|
|
* @input array The first array
|
|
|
|
* @input array The second array
|
|
|
|
*
|
|
|
|
* @returns bool true if intersect else false
|
|
|
|
*
|
|
|
|
* @since 3.1.1
|
|
|
|
*/
|
|
|
|
public static function intersect($a_array, $b_array): bool
|
|
|
|
{
|
|
|
|
// flip the second array
|
|
|
|
$b_array = array_flip($b_array);
|
|
|
|
|
|
|
|
// loop the first array
|
|
|
|
foreach ($a_array as $v)
|
|
|
|
{
|
|
|
|
if (isset($b_array[$v]))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|