-
Notifications
You must be signed in to change notification settings - Fork 1
array_flatten
Tonya Mork edited this page Dec 11, 2017
·
5 revisions
The array_flatten()
function flattens a multi-dimensional array into a single level (depth). By default, the entire array, meaning all depths, are flattened. However, you can specify the number of depths.
Note: The keys are not preserved in the flattened level.
array array_flatten(
array $subjectArray,
int $depth = INF
);
where,
$subjectArray
is the array to work on
$depth
is the depth to flatten, meaning the number of levels within the $subjectArray
to flatten. It defaults to infinite, meaning the entire array.
$user = [
'user_id' => 504,
'name' => 'Bob Jones',
'social' => [
'twitter' => '@bobjones',
],
];
$user = array_flatten($user);
/**
$user = [504, 'Bob Jones', '@bobjones'];
*/