Arr::dot

Posted on November 14, 2016

The Arr::dot function flattens a multi-dimensional array into a single level array that uses “dot” notation to indicate depth:

Example usage

$array = Arr::dot(['foo' => ['bar' => 'baz']]);
// ['foo.bar' => 'baz'];

$array = Arr::dot([ ['id' => 1, 'name' => 'John Doe'], ['id' => 2, 'name' => 'Jane Doe'],]);
// [
// '0.id' => 1,
// '0.name' => 'John Doe',
// '1.id' => 2,
// '1.name' => 'Jane Doe'
// ]

$array = Arr::dot( [ ['id' => 1, 'name' => 'John Doe'], ['id' => 2, 'name' => 'Jane Doe'], ], 'prefix');
// [
// 'prefix0.id' => 1,
// 'prefix0.name' => 'John Doe',
// 'prefix1.id' => 2,
// 'prefix1.name' => 'Jane Doe',
// ]

Parameters

array $array

string $prepend

Return Value

Array

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *