Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

Join array elements with a string – implode

Join array elements with a string

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

Join array elements with a glue string.

Parameters :
glue : Defaults to an empty string. This is not the preferred usage of implode() as glue would be the second parameter and thus, the bad prototype would be used.

Pieces : input array

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

Examples :

	<?php
	$pieces = array("Hello", "World,", "I", "am", "Here!");
	$gluedTogetherSpaces = implode(" ", $pieces);
	$gluedTogetherDashes = implode("-", $pieces);
	for($i = 0; $i < count($pieces); $i++){
		echo "Piece #$i = $pieces[$i] <br />";
	}
	echo "Glued with Spaces = $gluedTogetherSpaces <br />";
	echo "Glued with Dashes = $gluedTogetherDashes";
	?>

Display:
Piece #0 = Hello
Piece #1 = World,
Piece #2 = I
Piece #3 = am
Piece #4 = Here!
Glued with Spaces = Hello World, I am Here!
Glued with Dashes = Hello-World,-I-am-Here!

Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment