php implode multidimensional array

Solutions on MaxInterview for php implode multidimensional array by the best coders in the world

showing results for - "php implode multidimensional array"
Alessio
15 Jul 2019
1$users = [
2	'users' => ['user1@example.com','user2@example.com'],
3	'admins' => ['admin1@example.com', 'admin2@example.com']
4];
5
6// function to convert array of arrays to string
7function implodeArrayofArrays($array, $glue  = ', ') {
8        $output = '';
9        foreach ($array as $subarray) {
10            $output .= implode($separator, $subarray);
11        }
12        return $output;
13}
14
15echo implodeArrayofArrays($users);
16
17// "user1@example.com, user2@example.com, admin1@example.com, admin2@example.com"