Is there any good example of array manipulation in magento 2 using Class Magento\Framework\Stdlib\ArrayManager
and to use their function in my module like marge array, find any nodes etc.
I just wondering how to use in module.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityThis class is dedicated to handling/manipulating nested associative arrays. More specifically, heavily nested associative arrays. It is used primarily when handling data from UiComponents within DataProviders and Modifiers; which, are actually part of a complicated process of parsing XML files as associative arrays!
Most of the methods in the API abstract array traversal by representing them as "paths." (i.e. 'firstKey/secondKey/thirdKey' is equivalent to:
[firstKey] => [
[secondKey] => [
[thirdKey] => 'someValue'
]
]
where 'someValue'
is the value associated with the last key in the "path")
Below is a description of each method in the API and an example of how Magento uses them in their core code:
Checks if a path exits in a given associative array
This will retrieve the value of the key (or node) at the end of the path
Sets a value into a node, and returns the modified associative array
Sets a value into existing nodes and returns the modified array
Moves a value from one path, to another. If the path doesn't exist, the method provides the option to populate that path with the $overwrite parameter
Unfortunately, I couldn't find an example (outside the unit test) of this method being used in the core code :/
This is an abstraction for the PHP method array_replace_recursive. It allows you to do the same thing as the aforementioned SPL method, but staring at specified path
Creates an index (or indexes), given a path. It will create an empty array at the end of the path
Same story as Move(), couldn't find this being used anywhere in the code base...
Removes (or "unsets") a particular value based on a given path
Returns an array filled with paths where a specified index exists
Gets the first matching path for elements with specified indexes
An abstraction for array_slice that allows for retrieval/offsetting of a string sequence representing a path in an associative array