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

Implode error for PHP

I have a form where I've got three checkboxes like this: Wireless Cellular
Doug Molineux
  • 12,283
  • 25
  • 92
  • 144
4
votes
2 answers

How to build a dynamic MySQL INSERT statement with PHP

Hello This part of a form is showing columns names from mysql table (names of applications installed on a computer) and creating a form with YES/NO option or input type="text" box for additional privileges to a application.. How can I insert it…
Michal
  • 41
  • 1
  • 1
  • 4
4
votes
3 answers

array implode with '<', odd behavior

$b = array("one", "two", "three"); $z = implode('<', $b); var_dump($z); outputs: string(13) "one can anyone explain this. PHP 5.4.4
Robert
  • 10,126
  • 19
  • 78
  • 130
4
votes
5 answers

Easily Alternate Delimiters in a Join

I have a list of tuples like so (the strings are fillers... my actual code has unknown values for these): list = [ ('one', 'two', 'one'), ('one', 'two', 'one', 'two', 'one'), ('one', 'two', 'one', 'two', 'one', 'two', 'one'...) ] I would like…
Cassie
  • 292
  • 1
  • 3
  • 9
3
votes
3 answers

php implode multidimensional array to tab dilimited lines

I have a multidimensional array $BlockData[]which has 13 dimensions in it and 'n' number of array elements. I need to implode this array back to a single long string where the elements are separated by "\n" line feeds and the dimensions are…
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
3
votes
4 answers

Separate an array with comma and string PHP

I want to separate an array with comma and word. This is the code that i make: $array = array( 'user1', 'user2', 'user3', 'user4', 'user5' ); $last = array_pop( $array ); $string = count( $array ) ? implode( ", ", $array ) . " and " . $last :…
John
  • 171
  • 10
3
votes
1 answer

Why is exec() silently discarding bytes?

After a lot of struggling, I found out some behavior I can't explain / solve, so asking here for help. On our server (Ubuntu 16.04.5 LTS with PHP 7.0.30), we're using some tools outside of the 'httpdocs', which are called using exec() to get their…
Bazardshoxer
  • 545
  • 1
  • 5
  • 22
3
votes
4 answers

Convert an array of numeric byte values into a string with jq

I have the binary representation of an UTF-8 string as an array of numeric values, each in the range of 0..255. How to convert that array into the string using jq? The built-in implode deals with the codepoint arrays only. Besides, there's no…
tsul
  • 1,401
  • 1
  • 18
  • 22
3
votes
1 answer

Merge array and implode last element of a array by comma in php

I have following array, want to merge it and implode last element by comma. First two elements will always be the same,only the last elements will vary, want to implode it by comma. Input Array [dob] => Array ( [0] => Array …
Yabes Nadar
  • 209
  • 2
  • 11
3
votes
4 answers

Implode data from a Two-dimensional array

I think it should not be so difficult to solve but i can’t get the solution. I’m trying to implode an array in order to have this result : $new_array = "755, 646, 648, 260, 257, 261, 271, 764, ..." Here is my array : Array ( [0] => Array …
Sébastien Gicquel
  • 4,227
  • 7
  • 54
  • 84
3
votes
5 answers

Access and join two columns in an array separately

I have below array, Array ( [1] => Array ( [0] => Array ( [location] => X33 [usernumber] => 1 [order] => XX [part_number] => Hi ) …
rjcode
  • 1,193
  • 1
  • 25
  • 56
3
votes
4 answers

PHP - String Replace SyntaxError: illegal character

Output for $status Array ( [1] => 1 [2] => 0 [3] => 0 [4] => 4 [5] => 4 ) $color_code_string = implode(",",$status); Ouput 1,0,0,4,4 $color_code_string = str_replace("0","'#F00'",$color_code_string); $color_code_string =…
Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121
3
votes
3 answers

implode an array value

I've a multi-select attribute color. $color = $_product->getAttributeText('color'); $output = implode(',', $color); echo $output; $color gives an array value. If there are multiple values present for the color attribute, say 1. blue and 2. green,…
amitshree
  • 2,048
  • 2
  • 23
  • 41
3
votes
1 answer

PHP Calculate Every Permutation from 2D Array

I have been searching and scratching my head for days and I'm stuck between a rock and a hard place. After all my previous code runs, I am left with this array: Array ( [0] => Array ( [0] => 1 [1] => 3 ) [1] =>…
Nicholas Mordecai
  • 859
  • 2
  • 12
  • 33
3
votes
5 answers

Place Query Results into Array then Implode?

Basically I pull an Id from table1, use that id to find a site id in table2, then need to use the site ids in an array, implode, and query table3 for site names. I cannot implode the array correctly first I got an error, then used a while loop. With…
jason
  • 33
  • 1
  • 3