Download the PHP package lukascivil/treewalker without Composer
On this page you can find all versions of the php package lukascivil/treewalker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lukascivil/treewalker
More information about lukascivil/treewalker
Files in lukascivil/treewalker
Package treewalker
Short Description TreeWalker is a simple and small Library that will help you to work faster with manipulation of structures in PHP
License MIT
Informations about the package treewalker
TreeWalker
A simple and lightweight PHP library for manipulating nested structures — arrays, objects and JSON strings interchangeably.
Methods
| Method | Description |
|---|---|
getdiff() |
Returns the difference between two structures |
walker() |
Walks recursively through a structure, allowing edits and deletions |
structMerge() |
Merges two structures (first argument takes precedence) |
createDynamicallyObjects() |
Creates nested keys dynamically |
getDynamicallyValue() |
Reads a value by dynamic key path |
setDynamicallyValue() |
Sets a value by dynamic key path |
Live example
All methods accept and return any of the three supported structure types:
Requirements
- PHP >= 8.1
Installation
Usage
Initialization
getdiff()
Returns the difference between two structures, split into new, removed and edited keys.
Output:
Pass true as the third argument to get nested output instead of slash-delimited keys:
walker()
Walks recursively through the structure. The callback receives the parent array, the current key and the current value by reference, allowing in-place modification or deletion.
Output:
structMerge()
Merges two structures. Values from the first argument take precedence over the second.
Output:
createDynamicallyObjects()
Creates nested empty objects from a dynamic array of keys.
Output:
getDynamicallyValue()
Reads a value from a structure using a dynamic key path.
Output:
setDynamicallyValue()
Sets a value in a structure using a dynamic key path.
Output:
Development
Additional context
If you need the JavaScript equivalent for client-side structure comparison, see JsonDifference.
License
MIT © Lucas Cordeiro da Silva