Automattic\WooCommerce\Admin\Features\MarketingRecommendations

Init::object_to_array()public staticWC 1.0

Convert an object to an array. This is used to convert the specs to an array so that they can be returned by the API.

Method of the class: Init{}

No Hooks.

Return

Array.

Usage

$result = Init::object_to_array( $obj, $visited );
$obj(mixed) (required)
Object to convert.
$visited (passed by reference — &)
-
Default: array()

Init::object_to_array() code WC 9.7.1

public static function object_to_array( $obj, &$visited = array() ) {
	if ( is_object( $obj ) ) {
		if ( in_array( $obj, $visited, true ) ) {
			// Circular reference detected.
			return null;
		}
		$visited[] = $obj;
		$obj       = (array) $obj;
	}
	if ( is_array( $obj ) ) {
		$new = array();
		foreach ( $obj as $key => $val ) {
			$new[ $key ] = self::object_to_array( $val, $visited );
		}
	} else {
		$new = $obj;
	}
	return $new;
}