How to implode subarrays in a 2-dimensional array?
问题 I want to implode values in to a comma-separated string if they are an array: I have the following array: $my_array = [ "keywords" => "test", "locationId" => [ 0 => "1", 1 => "2"], "industries" => "1" ]; To achieve this I have the following code: foreach ($my_array as &$value) is_array($value) ? $value = implode(",", $value) : $value; unset($value); The above will also change the original array. Is there a more elegant way to create a new array that does the same as the above? I mean, implode