★ wanayoo — archive 1999 http://www.php.net/manual/it/function.implode.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Strings
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageFrench version of this pageHungarian version of this page
Strings
* AddCSlashes
* AddSlashes
* bin2hex
* Chop
* Chr
* chunk_split
* convert_cyr_string
* count_chars
* crypt
* echo
* explode
* flush
* get_html_translation_table
* get_meta_tags
* htmlentities
* htmlspecialchars
* implode
* join
* ltrim
* md5
* Metaphone
* nl2br
* Ord
* parse_str
* print
* printf
* quoted_printable_decode
* QuoteMeta
* rawurldecode
* rawurlencode
* setlocale
* similar_text
* soundex
* sprintf
* strcasecmp
* strchr
* strcmp
* strcspn
* strip_tags
* StripCSlashes
* StripSlashes
* stristr
* strlen
* strpos
* strrchr
* str_repeat
* strrev
* strrpos
* strspn
* strstr
* strtok
* strtolower
* strtoupper
* str_replace
* strtr
* substr
* substr_replace
* trim
* ucfirst
* ucwords
Manual: implode
View the source code for this pageSearch the site



Previous page
 htmlspecialchars
 Updated
Sun, 06 Aug 2000
join 
Next page


implode

(PHP3 , PHP4 )

implode -- Join array elements with a string

Description

string implode (string glue, array pieces)

Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.

Esempio 1. Implode() example


$colon_separated = implode (":", $array);
      

See also explode(), join(), and split().


User Contributed Notes: implode


jm@goemaere.com
31-Dec-1999 10:39
Same as join in Perl
A great function to construct SQL statements...



NOTuhyeah@php.net
02-Jan-2000 11:57
This function is usefull for concatenating strings for posting in forms, then expand in the receiving script.


m_esler@hotmail.com
07-Jan-2000 11:29
A good use for this function is to generate dynamic dropdown SELECT boxes derived from a column in a database.


An example of this would be to create a function called GetDistinctArray() which essentially returns an array generated from a query like
"SELECT DISTINCT $COLUMN FROM $TABLE".

Once you have an array say of distinct categories, implode lets you spit them out into a SELECT statement with:

echo '

<SELECT NAME="CATEGORY">';

$CATEGORY = "Foo";

$CatArray =
GetDistinctArray("CATEGORY",$DATABASE,$TABLE);

$OPTIONS = implode("<OPTION>",$CatArray);

echo '<SELECT NAME = "CATEGORY">';

print "<OPTION>$OPTIONS
</SELECT>";



The same could have been done by simply doing a query, looping through the array elements, but this is much cleaner and the function is reusable for any other dropdowns..



parker@chemistry.ohio-state.edu
27-Apr-2000 09:20
This function and the explode function should be referred to in the See Also section of the array function.

Coming from a perl background and not realizing that there is no way to dereference an entire array

@{$arrayref} works in perl, which works with lists and not array references in constructs like
foreach $variable (LIST)

Just a suggestion



 About Notes


Previous page
 htmlspecialchars
 Updated
Sun, 06 Aug 2000
join 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.