$element) { if (is_object($element)) { $this->_decorateArrayObject($element, $keyIsFirst, 0 === $index, $forceSetAll || 0 === $index); $this->_decorateArrayObject($element, $keyIsOdd, !$isEven, $forceSetAll || !$isEven); $this->_decorateArrayObject($element, $keyIsEven, $isEven, $forceSetAll || $isEven); $isEven = !$isEven; $index++; $this->_decorateArrayObject( $element, $keyIsLast, $index === $count, $forceSetAll || $index === $count ); } elseif (is_array($element)) { if ($forceSetAll || 0 === $index) { $array[$key][$keyIsFirst] = 0 === $index; } if ($forceSetAll || !$isEven) { $array[$key][$keyIsOdd] = !$isEven; } if ($forceSetAll || $isEven) { $array[$key][$keyIsEven] = $isEven; } $isEven = !$isEven; $index++; if ($forceSetAll || $index === $count) { $array[$key][$keyIsLast] = $index === $count; } } } return $array; } /** * Mark passed object with specified flag and appropriate value. * * @param \Magento\Framework\DataObject $element * @param string $key * @param bool $value * @param bool $isSkipped * @return void */ private function _decorateArrayObject($element, $key, $value, $isSkipped) { if ($isSkipped && $element instanceof \Magento\Framework\DataObject) { $element->setData($key, $value); } } /** * Expands multidimensional array into flat structure. * * Example: * * ```php * [ * 'default' => [ * 'web' => 2 * ] * ] * ``` * * Expands to: * * ```php * [ * 'default/web' => 2, * ] * ``` * * @param array $data The data to be flatten * @param string $path The leading path * @param string $separator The path parts separator * @return array * @since 101.0.0 */ public function flatten(array $data, $path = '', $separator = '/') { $result = []; $path = $path ? $path . $separator : ''; foreach ($data as $key => $value) { $fullPath = $path . $key; if (!is_array($value)) { $result[$fullPath] = $value; continue; } $result = array_merge( $result, $this->flatten($value, $fullPath, $separator) ); } return $result; } /** * Search for array differences recursively. * * @param array $originalArray The array to compare from * @param array $newArray The array to compare with * @return array Diff array * @since 101.0.0 */ public function recursiveDiff(array $originalArray, array $newArray) { $diff = []; foreach ($originalArray as $key => $value) { if (array_key_exists($key, $newArray)) { if (is_array($value)) { $valueDiff = $this->recursiveDiff($value, $newArray[$key]); if (count($valueDiff)) { $diff[$key] = $valueDiff; } } else { if ($value != $newArray[$key]) { $diff[$key] = $value; } } } else { $diff[$key] = $value; } } return $diff; } }