Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Maarch
maarchRM
Commits
19052a6b
Verified
Commit
19052a6b
authored
Nov 30, 2021
by
Cyril Vazquez
Browse files
Function to flatten data structures
parent
1534b913
Pipeline
#14672
failed with stages
in 54 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/laabs.php
View file @
19052a6b
...
...
@@ -1448,4 +1448,37 @@ class laabs
$message
=
$source
.
' '
.
$delay
.
's '
.
round
(
memory_get_usage
()
/
1000000
)
.
'/'
.
round
(
memory_get_peak_usage
()
/
1000000
)
.
'Mb'
;
static
::
log
(
$message
);
}
/**
* Flatten a data structure
* @param mixed $data
*
* @return array
*/
public
static
function
flatten
(
$data
,
&
$flat
=
[],
$path
=
null
)
{
if
(
$path
)
{
$flat
[
$path
]
=
$data
;
}
if
(
is_object
(
$data
))
{
if
(
!
empty
(
$path
))
{
$path
.
=
'.'
;
}
foreach
(
$data
as
$name
=>
$value
)
{
static
::
flatten
(
$value
,
$flat
,
$path
.
$name
);
}
return
$flat
;
}
if
(
is_array
(
$data
))
{
foreach
(
$data
as
$key
=>
$value
)
{
static
::
flatten
(
$value
,
$flat
,
$path
.
'['
.
$key
.
']'
);
}
return
$flat
;
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment