flatten_noptin_array( array $array, string $prefix = '' )

Flattens a multi-dimensional array containing merge tags.


Parameters Parameters

$array

(array) (Required)

$prefix

(string) (Optional)

Default value: ''


Top ↑

Return Return

(string[])


Top ↑

Source Source

File: includes/functions.php

function flatten_noptin_array( $array, $prefix = '' ) {
	$result = array();

	foreach ( $array as $key => $value ) {

		$_prefix = '' == $prefix ? "$key" : "$prefix.$key";

		$result[ $_prefix ] = 1;

		if ( is_array( $value ) ) {
			$result = array_merge( $result, flatten_noptin_array( $value , $_prefix ) );
		} else if ( is_object( $value ) ) {
			$result = array_merge( $result, flatten_noptin_array( get_object_vars( $value ), $_prefix ) );
		} else {

			if ( false === $value ) {
				$value = __( 'No', 'newsletter-optin-box' );
			}

			if ( true === $value ) {
				$value = __( 'Yes', 'newsletter-optin-box' );
			}

			$result[ $_prefix ] = $value;

			if ( strpos( $_prefix, '.0' ) !== false ) {
				$result[ str_replace( '.0', '', $_prefix ) ] = $value;
			}

		}

	}

	return $result;

}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.5.1Introduced.

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation