prop ?? null);" * @param mixed|null $input input to be checked in a javascript-type if condition * @return bool indicator if input is populated */ public static function issetJS( $input ): bool { if ( $input === 0 || $input == "" ) { return false; } return true; } /** * Checks if the incoming string is containing a regex pattern. * @param string $input string to verify * @param string $subject subject to check, usually empty string * @return bool true if regex pattern, false if not */ public static function isRegex( string $input, string $subject = "" ): bool { /** * Ignoring preg_match phpcs error here, since this is the fastest variant: 582 ms for MMLmhchemTestLocal, * 835 ms for the try catch version of this, 735 ms for the version deactivating error handler * during function call. * See: https://stackoverflow.com/questions/16039362/how-can-i-suppress-phpcs-warnings-using-comments */ // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged return !( @preg_match( $input, $subject ) === false ); } /** * Checks if an array is an associative array * @param array $array to check * @return bool true if associative, otherwise false */ public static function isAssoc( array $array ): bool { return ( $array !== array_values( $array ) ); } /** * @param array &$a * @param mixed|null $b */ public static function concatArray( &$a, $b ) { if ( self::issetJS( $b ) ) { if ( is_array( $b ) && ( self::isAssoc( $b ) ) ) { $a[] = $b; } elseif ( is_array( $b ) && !self::isAssoc( $b ) ) { foreach ( $b as $value ) { $a[] = $value; } } else { $a[] = $b; } } } }