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
10
votes
4 answers

Implode an array without first element

I have an array like this: [0]=>array( [cname] => ABC [12] => 60.7500 [13] => 33.7500 [14] => 47.7500 [15] => 86.0000 [16] => 62.2500 [17] => 59.5000 [18] =>…
RK.
  • 973
  • 5
  • 19
  • 45
9
votes
6 answers

implode() string, but also append the glue at the end

Trying to use the implode() function to add a string at the end of each element. $array = array('9898549130', '9898549131', '9898549132'); $attUsers = implode("@txt.att.net,", $array); print($attUsers); Prints…
Ryan Litwiller
  • 497
  • 5
  • 24
9
votes
3 answers

Implode with double quotes as separator

I have this right now: $_words = "'".implode("','", $array_of_words)."'"; Which gives me a string like: 'word','word2','word3' How can I modify that to get "word","word2","word3" Thanks
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
9
votes
1 answer

Coding Implode In Twig

How can one use the equivalent of the implode function in a Twig environment? For example, the contents of the variable $data1 = "input your name" and the variable $data2 = "input your address". How to create a variable $result = "input your name,…
user1798945
  • 145
  • 1
  • 2
  • 7
8
votes
1 answer

How to echo out all elements of php array at once?

hi friends I have a php array for eg. $mob_numbers= array(12345674, 12345675, 12345676,12345677); I want to eacho out all of them at once so that it appears 12345674,12345675,12345676,12345677 (with comma) . How do i do it ? I tried array…
ktm
  • 6,025
  • 24
  • 69
  • 95
8
votes
5 answers

Is this overkill, or good use of CakePHP's HTML helper?

I just reformatted the default layout of my CakePHP application. I eliminated as much in-line html as possible by putting almost everything inside the html helper methods. It was fun, but I'm wondering what benefit I've gained from this exercise,…
Stephen
  • 18,827
  • 9
  • 60
  • 98
8
votes
2 answers

How can I make ArrayIterator or ArrayObject work with implode?

I'm having a few problems with ArrayIterator (And, indeed, the same problem with ArrayObject). For 99% of everything, my extended ArrayIterator behaves like an array and is working great. Unfortunately, implode() does not like being given an…
Oli Comber
  • 311
  • 2
  • 11
8
votes
1 answer

Serialize or Implode

I need to store lots of two-dimensional arrays inside database and was not sure what to use: serialize or implode. So I did a few tests, to find out which one is working faster and came to the conclusion it was serialize: Execution times:…
Peon
  • 7,902
  • 7
  • 59
  • 100
7
votes
4 answers

PHP: strip the tags off the value inside array_values()

I want to strip the tags off the value inside array_values() before imploding with tabs. I tried with this line below but I have an error, $output = implode("\t",strip_tags(array_keys($item))); ideally I want to strip off the line breaks, double…
Run
  • 54,938
  • 169
  • 450
  • 748
7
votes
2 answers

PHP array and implode with blank/null values

I have a array which i generated by values in a database, the example is below: $addressarray = array($results['client']->client_city, $results['client']->client_county, $results['client']->client_postcode); The values are entered by the user using…
snookian
  • 863
  • 6
  • 13
  • 35
7
votes
5 answers

Put all indexs of array in a comma separated string

I have an array that looks like this: array('first' => 'value1', 'second' => 'value2', ...); How can I get all the keys and put them in a comma separated string? At the very end I need something like this, to do a query: values IN…
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
6
votes
4 answers

How to convert a associative array into a string using implode function

This is my associative array . Array ( [month] => June [sale] => 98765 ) Array ( [month] => May [sale] => 45678 ) Array ( [month] => April [sale] => 213456 ) Array ( [month] => August [sale] => 23456 ) Array ( [month] => July [sale] => 12376…
Nishank Magoo
  • 301
  • 4
  • 12
6
votes
1 answer

PHP implode not working for big array?

I have an array with 30k items, and implode returns nothing. No error message, no memory problems, just nothing. If I use array_slice and slice the array to 100 items, it works fine. It also works for 7k array, but not for this one. However, in…
Honza
  • 323
  • 3
  • 14
5
votes
9 answers

display contents of .txt file using php

using this code
"; } ?> i can display the contants of any txt file in the…
vache
  • 321
  • 4
  • 5
  • 13
5
votes
8 answers

Replace the last comma with an & sign

I have searched everywhere but can't find a solution that works for me. I have the following: $bedroom_array = array($studio, $one_bed, $two_bed, $three_bed, $four_bed); For this example lets say: $studio = '1'; $one_bed = '3'; $two_bed = '3'; I…
iain
  • 407
  • 3
  • 20
1 2
3
49 50