Questions tagged [implode]

implode() is a PHP function that joins together an array (optionally based on a 'glue' (inverse delimiter)) and returning a string.

implode() is a PHP function that joins together an array (optionally based on a 'glue' (inverse delimiter - defaults to an empty string) and returning a string.

string implode ( string $glue , array $pieces )
string implode ( array $pieces )

Example

$array = array("a", "b", "c", "d");
print_r(implode(" ", $array));
print_r(implode($array));

returns:

a b c d
abcd
749 questions
26
votes
9 answers

How to use implode a column from an array of stdClass objects?

I have an array of stdClass objects and I want to build a comma separated list using one specific field of all those stdClass objects. My array looks like this: $obj1 = stdClass Object ( [foo] => 4 [bar] => 8 [foo-bar] => 15 ); $obj2 = stdClass…
ubiquibacon
  • 10,451
  • 28
  • 109
  • 179
24
votes
4 answers

PHP, add a newline with implode

I'm trying to add a newline \n, in my foreach statement with implode. My code: $ga->requestReportData($profileId,array('country'),array('visits')); $array = array(); foreach($ga->getResults() as $result){ $array[] =…
Mathieu
  • 797
  • 2
  • 6
  • 24
23
votes
1 answer

How to convert an array into comma separated strings in smarty template?

I've an array titled $preview_data assigned to smarty template as follows: Array ( [applicable_states] => Array ( [0] => 1 [1] => 3 [2] => 4 [3] => 10 [4] => 11 ) ) Now…
PHPLover
  • 1
  • 51
  • 158
  • 311
22
votes
2 answers

I killed rvm now I have a bash message

I decided to kill rvm, using the rvm implode command. When I run cd in osx terminal I get this message: ~/projects $ cd -bash: /Users/boris/.rvm/scripts/initialize: No such file or directory -bash: /Users/boris/.rvm/scripts/hook: No such file or…
JZ.
  • 21,147
  • 32
  • 115
  • 192
22
votes
5 answers

Multidimensional Array PHP Implode

In terms of my data structure, I have an array of communications, with each communications_id itself containing three pieces of information: id, score, and content. I want to implode this array in order to get a comma separated list of ids, how do I…
Spencer
  • 21,348
  • 34
  • 85
  • 121
17
votes
1 answer

PHP: is the implode() function safe for multibyte strings?

The explode() function has a correlating multibyte-safe function in mb_split(). I don't see a correlating function for implode(). Does this imply that implode is already safe for multibyte strings?
David Jones
  • 10,117
  • 28
  • 91
  • 139
15
votes
3 answers

How to remove prefix in array keys

I try to remove a prefix in array keys and every attempt is failing. What I want to achieve is to: Having: Array ( [attr_Size] => 3 [attr_Colour] => 7 ) To Get: Array ( [Size] => 3 [Colour] => 7 ) Your help will be much appreciated...
rat4m3n
  • 1,201
  • 2
  • 16
  • 23
14
votes
19 answers

Custom array_chunk to prioritize filling columns as much as possible

I have an array which can have several items in it, e.g: Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 etc I need the quickest way to restructure this array so that it has at most X items. So if I say that X is 3, the resulting array must be: Item 1 ,…
rockstardev
  • 13,479
  • 39
  • 164
  • 296
13
votes
9 answers

PHP Implode Associative Array

So I'm trying to create a function that generates a SQL query string based on a multi dimensional array. Example: function createQueryString($arrayToSelect, $table, $conditionalArray) { $queryStr = "SELECT ".implode(", ", $arrayToSelect)." FROM…
st4ck0v3rfl0w
  • 6,665
  • 15
  • 45
  • 48
13
votes
3 answers

using implode for stdClass Objects in php

foreach($categories as $category) { print_r($category); } The code above gives me the following result. stdClass Object ( [category_Id] => 4 [category_Title] => cat 4 ) stdClass Object ( [category_Id] => 7 [category_Title] =>…
Afshin
  • 2,427
  • 5
  • 36
  • 56
13
votes
5 answers

Trying to join a two-dimensional array in Javascript

I'm trying to convert a two-dimensional array to a string in order to store it in the localStorage array. However, there is something wrong with this code I cannot identify: for(x in array) { if(array[x] instanceof Array) { array[x] =…
Arda Xi
  • 2,616
  • 3
  • 19
  • 24
12
votes
3 answers

Implode a column of values from a two dimensional array

I've got an array like this: Array ( [0] => Array ( [name] => Something ) [1] => Array ( [name] => Something else ) [2] => Array ( [name] => Something…
qwerty
  • 575
  • 3
  • 6
  • 8
11
votes
4 answers

foreach with array_chunk in php and with multiple arrays

I'm relatively new to php and I've been trying all day long to get this to work. I have a multiple array and want to echo each one in a specific format, and in groups. So i've gone through stackoverflow and found this help:
Aron
  • 135
  • 1
  • 1
  • 5
11
votes
3 answers

implode an array into a comma separated string from mysql query

For the last 1 1/2 days I've been trying to store 16 row id's into a string and separate each id with a comma. The array I am getting is from MySQL. The error I am getting is implode() function:passed invalid…
anjel
  • 1,355
  • 4
  • 23
  • 35
10
votes
3 answers

Implode array of values as well as its keys

I'm trying to implode an array of both its keys and values. I can easily get the keys with the implode, but find I have to repeat myself for the keys. Currently I am doing this: $values = array( 'id' => $sel['id'], …
Hailwood
  • 89,623
  • 107
  • 270
  • 423
1
2
3
49 50