phrity/util-transformer
Lightweight PHP utility for transforming values between types. Provides transformers with canTransform()/transform(), plus resolvers to chain and recurse converters. Includes JSON/flatten decoders and converters for basic types, DateTime, enums, Stringable, Throwable and more.
Documentation / Flatten Decoder
The FlattenDecoder expands array with flattened keys to nested array.
// Convert to anything
$decoder = new FlattenDecoder('_');
$flattened = [
'a1_b1_c1' => 111,
'a1_b1_c2' => 112,
'a2' => 2,
];
$decoder->canTransform($flattened); // -> bool
$result = $decoder->transform($flattened); // -> mixed output
/*
$result => [
'a1' => [
'b1' => [
'c1' => 111,
'c2' => 112,
],
],
'a2' => 2,
];
*/
How can I help you explore Laravel packages today?