Imploding an array of arrays in php

  php

I have the following array:

$names = [
    ['Joe','Moe','Joey'],
    ['John','Doe','Curly'],
    ['Jimmy','Fallon','Funny']
];

What I am trying to do, is implode into a string that looks like this:

"('Joe','Moe','Joey'),('John','Doe','Curly'),'Jimmy','Fallon','Funny')"

The implode function does not work on an array of arrays, so I did the following, and it accomplishes what I need:

$strings = [];
foreach ($names as $name) {
    $strings[] = '('.implode(',',$name).')';
}
$output = implode(',',$strings);

My question is: is there a cleaner way to do this?

Source: Ask PHP

LEAVE A COMMENT