REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 3.07 KB
Close
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/Internal/Utilities/ArrayUtil.php
Text
Base64
<?php declare( strict_types=1 ); namespace Automattic\WooCommerce\Internal\Utilities; /** * A class of utilities for dealing with arrays. */ class ArrayUtil { /** * Determines if the given array is a list. * * An array is considered a list if its keys consist of consecutive numbers from 0 to count($array)-1. * * Polyfill for array_is_list() in PHP 8.1. * * @param array $arr The array being evaluated. * * @return bool True if array is a list, false otherwise. */ public static function array_is_list( array $arr ): bool { if ( function_exists( 'array_is_list' ) ) { return array_is_list( $arr ); } if ( ( array() === $arr ) || ( array_values( $arr ) === $arr ) ) { return true; } $next_key = -1; foreach ( $arr as $k => $v ) { if ( ++$next_key !== $k ) { return false; } } return true; } /** * Merge two lists of associative arrays by a key. * * @param array $arr1 The first array. * @param array $arr2 The second array. * @param string $key The key to merge by. * * @return array The merged list sorted by the key values. */ public static function merge_by_key( array $arr1, array $arr2, string $key ): array { $merged = array(); // Overwrite items in $arr1 with items in $arr2 if they have the same key entry value. // The rest of items in $arr1 will be appended. foreach ( $arr1 as $item1 ) { $found = false; foreach ( $arr2 as $item2 ) { if ( $item1[ $key ] === $item2[ $key ] ) { $merged[] = array_merge( $item1, $item2 ); $found = true; break; } } if ( ! $found ) { $merged[] = $item1; } } // Append items from $arr2 that are don't have a corresponding key entry value in $arr1. foreach ( $arr2 as $item2 ) { $found = false; foreach ( $arr1 as $item1 ) { if ( $item1[ $key ] === $item2[ $key ] ) { $found = true; break; } } if ( ! $found ) { $merged[] = $item2; } } // Sort the merged list by the key values. usort( $merged, function ( $a, $b ) use ( $key ) { return $a[ $key ] <=> $b[ $key ]; } ); return array_values( $merged ); } /** * Recursively filters null values from an array. * * This method removes all null values from the array, including nested arrays. * Array keys are preserved for associative arrays. For lists (sequential numeric * keys starting from 0), the array is reindexed to maintain the list structure. * * @param array $arr The array to filter. * * @return array The filtered array with null values removed. */ public static function filter_null_values_recursive( array $arr ): array { $is_list = self::array_is_list( $arr ); $filtered = array(); foreach ( $arr as $key => $value ) { // Skip null values. if ( is_null( $value ) ) { continue; } // Recursively filter nested arrays. if ( is_array( $value ) ) { $filtered[ $key ] = self::filter_null_values_recursive( $value ); } else { $filtered[ $key ] = $value; } } // Reindex if the original array was a list. return $is_list ? array_values( $filtered ) : $filtered; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 14
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
ArrayUtil.php
3.07 KB
lrw-r--r--
2025-11-24 23:10:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
BlocksUtil.php
2.36 KB
lrw-r--r--
2026-01-26 10:40:36
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
COTMigrationUtil.php
6.04 KB
lrw-r--r--
2025-05-12 21:07:28
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
DatabaseUtil.php
16.10 KB
lrw-r--r--
2024-09-23 20:44:04
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
FilesystemUtil.php
7.63 KB
lrw-r--r--
2026-03-30 17:12:24
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
HtmlSanitizer.php
3.10 KB
lrw-r--r--
2024-04-30 19:35:34
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
LegacyRestApiStub.php
6.65 KB
lrw-r--r--
2024-12-18 22:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
PluginInstaller.php
14.01 KB
lrw-r--r--
2024-12-18 22:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ProductUtil.php
1.16 KB
lrw-r--r--
2025-10-06 17:56:06
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Types.php
1.97 KB
lrw-r--r--
2024-12-16 15:24:32
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
URL.php
13.10 KB
lrw-r--r--
2024-12-16 15:24:32
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
URLException.php
191 B
lrw-r--r--
2022-04-20 06:50:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Users.php
9.47 KB
lrw-r--r--
2026-02-23 17:58:34
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
WebhookUtil.php
5.37 KB
lrw-r--r--
2024-12-18 22:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).