-
Notifications
You must be signed in to change notification settings - Fork 1
array_flatten_into_delimited_list
Tonya Mork edited this page Dec 11, 2017
·
2 revisions
The array_flatten_into_delimited_list()
function flattens a multi-dimensional array and then converts it into a delimited list. This function uses array_flatten
.
array array_flatten_into_delimited_list(
array $subjectArray,
string $delimiter = ','
);
where,
$subjectArray
is the array to work on
$delimiter
is the delimiter to use for the returned list. Default is ',', for a comma-separated list.
For this given subject array:
$user = [
'user_id' => 504,
'name' => 'Bob Jones',
'social' => [
'twitter' => '@bobjones',
],
];
The default of ','
gives you:
$user = array_flatten_into_delimited_list($user);
// $user = '504,Bob Jones,@bobjones';
Or when you specify a delimiter, you would get:
$user = array_flatten_into_delimited_list($user, ' | ');
// $user = '504 | Bob Jones | @bobjones';