That more often going to be the case than not. Let us look at what these are and some examples of how we can encode each of these into JSON - Indexed Array to JSON. What I meant to imply is you can use array_column and array_map interchangeably in this endeavor, but implode() to my knowledge is the only way to take an array and turn it into a delimited string (apart from coding a loop). On the contrary, I like array_column, that is what I was originally searching for when I looked through the php docs to begin with, but when I didn’t find it, I resorted to array_map. PHP allows a very simple way to declare a multidimensional array in PHP using the keyword ‘array’. implode() can, for historical reasons, accept its parameters in either order. For completeness, I will add a function that merges the key sequence by a given separator and a function that preserves the last n keys, where n is arbitrary. my goal is to create a string like this: 1603,1802,2255. but i start out with this multidimensional array: Array ([0] => Array ([device_id] => 1603 For example, I have the following array: I would like to show the job_type value separated by a comma. Nested arrays mean array containing the array. The implode() function takes an array, joins it with the given string, and returns the joined string. These two functions only take one array at a time to convert it into a string. Other functions below create a one-dimensional array preserving the last key. To fix this particular error, we would need to loop through the array like so: We could als… [ot]PHP 5.5.0 might get a new function, array_column(), that would make life easier here: echo implode(', ', array_column($array, 'job_type')); Implode isn’t the only way to get a string representation of an array that can be converted back to an array. The PHP has an implode function which helps to convert PHP array values into a string. Thanks, but was looking for something a little cleaner Any ideas how to do it using array_map? The following script shows how the implode() function can be used to join the values of a two-dimensional array. Writer behind An Exploring South African. It’s been a long day, my brain has started to shut down…, Powered by Discourse, best viewed with JavaScript enabled. View all posts by Craig Lotter →. Quickest way to restructure an array? The implode function Video You may also watch a short video of this tutorial. The echo statement can be used to output strings or scalar values. A South African software developer at Touchwork, Craig Lotter is a husband to a cake baker, father to two young girls, and someone who is constantly looking for new places to explore. implode() is a built-in function of PHP that generates a string value by combining the elements of an array with a delimiter. Most of the time we have to perform an operation on an array to bring all values in a string. However, for consistency with explode(), you should use the documented order of arguments. Click to share on Twitter (Opens in new window), Click to share on Facebook (Opens in new window), Click to share on Reddit (Opens in new window), Click to share on Pinterest (Opens in new window). In this article, we are using two methods to convert array to string. Two dimensional Array:- Using Multidimensional Arrays in PHP 19 July 2010 / 11 Comments Array elements in PHP can hold values of any type, such as numbers, strings and objects. As you say, he hasn’t mentioned why he’s doing this so why second guess? Multidimensional Array. multidimensional - php shuffle associative array . In any event, if those strings contain commas (and they’re free form it seems so they could) implode isn’t the right tool, even with array_column. array_map returns another array - so that won’t put you any further forward. I don't have time for myself any more. Array Multidimensional