Automattic\WooCommerce\Blueprint

Util::index_arraypublic staticWC 1.0

Index an array using a callback function.

Method of the class: Util{}

No Hooks.

Returns

Array.

Usage

$result = Util::index_array( $array, $callback );
$array(array) (required)
The array to be indexed.
$callback(callable) (required)
The callback function to be called for each element.

Util::index_array() code WC 9.9.5

public static function index_array( $array, $callback ) {
	$result = array();
	foreach ( $array as $key => $value ) {
		$new_key            = $callback( $key, $value );
		$result[ $new_key ] = $value;
	}
	return $result;
}